简体   繁体   English

Django-我有一个具有简单视图的简单应用程序-为什么每个URL请求都会调用两次?

[英]Django - I have a simple app with a simple view - why does it get called twice for every url request?

MyProj/myproj/urls.py: MyProj / myproj / urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^accounts/login/$', 'django.contrib.auth.views.login'),
    url(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login'),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^', include('apps.data.urls')),
)

MyProj/apps/data/urls.py: MyProj / apps / data / urls.py:

from django.conf.urls import patterns, url

urlpatterns = patterns('',
   url('^tasks/sync_database/', 'apps.data.views.sync_database'),
)

MyProj/apps/data/views.py: MyProj / apps / data / views.py:

from .tasks import sync_database as sync_database_task
from django.shortcuts import redirect

def sync_database(request):
    sync_demand_stacks_task()
    return redirect('/')

The task takes about 5 minutes to run. 该任务大约需要5分钟才能运行。 I expect that when I visit the url localhost:8000/tasks/sync_database/ that the web page should block for the duration of the time it takes the task to run, then show me the home page at url localhost:8000/ . 我希望当我访问url localhost:8000/tasks/sync_database/ ,该网页应在任务运行期间一直处于阻塞状态,然后向我显示url localhost:8000/的主页。

This does happen, but instead of running the task just once it runs it twice. 确实发生了,但是不是运行一次任务而是将其运行两次。 What gives? 是什么赋予了?

EDIT: I see this output in the console at the very end of the first request: 编辑:我在第一个请求的末尾在控制台中看到此输出:

127.0.0.1 - - [20/Feb/2014 15:18:43] "GET /tasks/sync_database/? HTTP/1.1" 500 -

I'm wondering where this URL with a question mark appended comes from. 我想知道这个带有问号的URL的来源。

使我的网站图标正常工作显然使问题消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM