使用参数'()'和关键字参数'{}'找不到'index'。尝试过0种模式:[]

时间:2014-01-08 10:57:41

标签: python django python-3.3 django-registration django-1.6

我正试图让django-register在我的网站上工作,但我一直收到这个我不明白的错误

我在Python 3.3上使用django 1.6

NoReverseMatch at /accounts/register/
Reverse for 'index' with arguments '()' and keyword arguments '{}' not     found. 0 pattern(s) tried: []
    Request Method: GET
Request URL:    http://127.0.0.1:8000/accounts/register/
Django Version: 1.6.1
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location: D:\Programming\Py33\lib\site-packages\django\core\urlresolvers.py in _reverse_with_prefix, line 429
Python Executable:  D:\Programming\Py33\python.exe
Python Version: 3.3.3
Python Path:    
['D:\\Programming\\GItHub\\photobyte\\PhotoByte',
 'D:\\Programming\\Py33\\lib\\site-packages\\setuptools-2.0.3dev-py3.3.egg',
 'C:\\WINDOWS\\SYSTEM32\\python33.zip',
 'D:\\Programming\\Py33\\DLLs',
 'D:\\Programming\\Py33\\lib',
 'D:\\Programming\\Py33',
 'D:\\Programming\\Py33\\lib\\site-packages']
Server time:    Wed, 8 Jan 2014 02:49:17 -0800
Error during template rendering

这是错误的HTML代码

抱怨第14行

In template D:\Programming\GItHub\photobyte\PhotoByte\templates\base.html, error at line 14
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
4   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5   
6   <head>
7       <link rel="stylesheet" href="/style.css" />
8       <title>{% block title %}User test{% endblock %}</title>
9   </head>
10  
11  <body>
12      <div id="header">
13          {% block header %}
14      <a href="{% url 'index' %}">{% trans "Home" %}</a> | 
15  
16      {% if user.is_authenticated %}
17      {% trans "Logged in" %}: {{ user.username }} 
18      (<a href="{% url 'auth_logout' %}">{% trans "Log out" %}</a> | 
19      <a href="{% url 'auth_password_change' %}">{% trans "Change password" %}</a>)
20      {% else %}
21      <a href="{% url 'auth_login' %}">{% trans "Log in" %}</a>
22      {% endif %}
23      <hr />
24          {% endblock %}

这是我项目的Urls.py

urlpatterns = patterns('',
    (r'^ImageUpload/', include('ImageUpload.urls')),
    (r'^accounts/', include('registration.backends.default.urls')),
    (r'^$', RedirectView.as_view(url='/ImageUpload/list/')), # Just for ease of use.
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

有人可以解释错误的含义吗?

2 个答案:

答案 0 :(得分:15)

它抱怨第14行,因为Django无法确定urls.py文件中名为“index”的url。我没有在上面看到名为“index”的URL。您的主页的URL模式在哪里/是什么?

答案 1 :(得分:3)

当URL匹配表达式具有参数但在模板中没有传递反向时,会发生这种情况。