【问题标题】:Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []未找到带有参数“()”和关键字参数“{}”的“索引”的反向操作。尝试了 0 种模式:[]
【发布时间】:2014-01-26 10:22:38
【问题描述】:

我正在尝试让 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)

有人能解释一下这个错误是什么意思吗?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 我对 django 的工作方式非常陌生。我认为它会包含在 django-registration.backends.defualt.urls 中。目前我没有主页。因此,如果我添加了一个具有名称索引的 url,它会重定向到那个?
    • 是的!只需执行 urlpatterns = patterns('', (r'^home/", home, name="home"), (r'^ImageUpload/', include('ImageUpload.urls')), (r'^accounts/ ', include('registration.backends.default.urls')), (r'^$', RedirectView.as_view(url='/ImageUpload/list/')), # 只是为了方便使用。) + static( settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    • 你先生真棒。谢谢你解释:)
    【解决方案2】:

    当 URL 匹配表达式有参数但模板中没有传入参数时会发生这种情况。

    【讨论】:

      猜你喜欢
      • 2016-11-21
      • 2014-11-23
      • 2017-01-06
      • 2018-07-12
      • 2016-05-08
      • 2016-08-27
      • 2017-05-04
      • 1970-01-01
      • 2016-03-21
      相关资源
      最近更新 更多