2014-02-07 310 views
0

試圖在Django教程調查項目中進行django註冊工作。django註冊 - NoReverseMatch at/accounts/login/at/accounts/login/

我使用Django 1.6,Django的註冊1.0和django-registration-templates

當我嘗試訪問

http://localhost:8000/accounts/login/ 

我得到

NoReverseMatch at /accounts/login/ 

Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 

線模板,mysite的/templates/base.html,錯誤報告中引用的是:

<a href="{% url 'index' %}">{% trans "Home" %}</a> | 

而且我確實有名爲「指數」的URL在我polls.url:

urlpatterns = patterns('', 
    url(r'^$', views.IndexView.as_view(), name='index'), 
    url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'), 
    url(r'^(?P<pk>\d+)/results/$', views.ResultsView.as_view(), name='results'), 
    url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name='vote'), 
) 

所以我覺得應該工作?幫幫我 ?


EDIT 1

polls.urls:

from django.conf.urls import patterns, url 

from polls import views 

urlpatterns = patterns('', 
    url(r'^$', views.IndexView.as_view(), name='index'), 
    url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'), 
    url(r'^(?P<pk>\d+)/results/$', views.ResultsView.as_view(), name='results'), 
    url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name='vote'), 
) 

mysite.urls:

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

admin.autodiscover() 

urlpatterns = patterns('', 
    url(r'^polls/', include('polls.urls', namespace="polls")), 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^accounts/', include('registration.backends.default.urls')), 
) 

registration.urls:

""" 
Backwards-compatible URLconf for existing django-registration 
installs; this allows the standard ``include('registration.urls')`` to 
continue working, but that usage is deprecated and will be removed for 
django-registration 1.0. For new installs, use 
``include('registration.backends.default.urls')``. 

""" 

import warnings 

warnings.warn("include('registration.urls') is deprecated; use include('registration.backends.default.urls') instead.", 
       DeprecationWarning) 

from registration.backends.default.urls import * 

回答

3

好,我在這裏找到了這個問題。名爲「指數」的網址在polls.urls定義,因此在模板內我需要改變:

<a href="{% url 'index' %}">{% trans "Home" %}</a> 

<a href="{% url 'polls:index' %}">{% trans "Home" %}</a> 

正如Django 1.6 documention of the url tag並提到我在這裏引用爲了方便:

如果你想獲取一個命名空間的URL,指定完全 限定名稱:

{%URL「MYAPP:視圖名」%}

這將遵循正常的命名空間URL的解決策略, 包括使用上下文提供的任何提示,以當前 應用。