2014-10-01 88 views
1

我正在爲運行在Nginx服務器上的Django站點設置登錄系統。我得到以下調試404頁面:Django沒有反映對urls.py的更改

Using the URLconf defined in it.urls, Django tried these URL patterns, in this order: 
^admin/ 
^login/ [name='main_login'] 
^$ [name='index'] 
^laptops/ 
^assets/ 
^mardes/ 
^users/ 
^jobs/ 
^static\/(?P<path>.*)$ 
The current URL, account/login/, didn't match any of these. 

這似乎是使用舊版本的it.urls文件;目前看起來是這樣的:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns 
from django.conf.urls import patterns, include, url 
from django.views.generic import TemplateView 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    url(r'^admin/', include(admin.site.urls)           ), 
    url(r'^account/', include('account.urls', namespace='account'), name='account'  ), 
    url(r'^laptops/', include('laptops.urls', namespace='laptops')      ), 
    url(r'^assets/', include('assets.urls', namespace='assets')      ), 
    url(r'^mardes/', include('mardes.urls', namespace='mardes')      ), 
    url(r'^users/', include('users.urls', namespace='users')      ), 
    url(r'^jobs/', include('jobs.urls', namespace='jobs')      ), 
    url(r'^',  TemplateView.as_view(template_name='it/index.html'), name='index' ), 
) + staticfiles_urlpatterns() 

正如你所看到的,它沒有r'^ login /'模式。

我在我的settings.py文件中將LOGIN_URL設置爲'/ account/login /',但是@login_required裝飾器正在加載'/ login /'。當我在@login_required調用中指定login_url ='/ account/login'時,新URL也會被忽略。

我已重新啓動Nginx(通過啓動和停止,並運行'重新啓動'),這並沒有什麼不同。我還在nginx.conf文件中設置了'sendfile = off'。我猜測有緩存存儲在某處(回覆:How to clear the cache of nginx?)。

如果您需要更多詳細信息,請讓我知道。

+0

你試過刪除所有'pyc'文件嗎? '找。 -name \ *。pyc -type f -delete' – michaelb 2014-10-01 14:58:57

+0

@michaelb是的,我確實嘗試過,沒有更改,不幸的 – bcvery1 2014-10-01 15:06:47

+0

你如何運行django服務器?通過uwsgi ...? – michaelb 2014-10-01 15:10:15

回答

2

Nginx不會單獨運行Django,但它應該與一個wsgi應用程序服務器(如uwsgi或​​)進行交互。

也許你應該重新啓動wsgi應用服務器而不是nginx。

+0

完全忘了uwsgi,謝謝! – bcvery1 2014-10-01 15:21:37

+0

對於Gunicorn:'sudo service gunicorn restart' – 2017-07-13 18:40:27

0

good catch @ bcvery1。對於那些通過乘客運行django應用的人來說,重新啓動nginx或重新創建restart.txt文件也應該可以查看這些更改。