在/accounts/signup/页面出现了Django-allauth错误的NoReverseMatch。

3

我在我的urls.py文件中有这段代码:

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

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^profile/', include('userProfile.urls')),
]

以下是userProfile.urls.py文件内容:

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

from .views import (
    profile_user,
)

urlpatterns = [
    url(r'^(?P<id>[0-9]+)/profile/$', profile_user),
]

我遇到了一个错误,错误信息为“在/accounts/signup处找不到匹配项(NoReverseMatch)”。我在某个地方读到说问题可能出现在urls.py文件中,但我不知道具体原因。如果有人能帮忙解决这个问题,那就太好了。上一次我检查时一切正常,现在出了点问题。谢谢。

我知道这个错误可能不够清晰,所以我把整个错误复制了下来:

NoReverseMatch at /accounts/login/
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/login/
Django Version: 1.9.5
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Exception Location: C:\Python27\lib\site-packages\django\core\urlresolvers.py in _reverse_with_prefix, line 508
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.11
Python Path:    
['D:\\Programiranje\\Python\\Projekat ISA\\ProjekatRestorani',
 'C:\\WINDOWS\\SYSTEM32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages']
Server time:    Thu, 19 May 2016 12:03:20 +0000
Error during template rendering

In template C:\Python27\lib\site-packages\allauth\templates\account\login.html, error at line 14
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
4   {% load account socialaccount %}
5   
6   {% block head_title %}{% trans "Sign In" %}{% endblock %}
7   
8   {% block content %}
9   
10  <h1>{% trans "Sign In" %}</h1>
11  
12  {% get_providers as socialaccount_providers %}
13  
14  {% if socialaccount_providers %}
15  <p>{% blocktrans with site.name as site_name %}Please sign in with one
16  of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
17  for a {{ site_name }} account and sign in below:{% endblocktrans %}</p>
18  
19  <div class="socialaccount_ballot">
20  
21    <ul class="socialaccount_providers">
22      {% include "socialaccount/snippets/provider_list.html" with process="login" %}
23    </ul>

但那不是我的login.html代码...这是我在login.html文件中的内容:
{% extends "base.html" %}
{% load i18n %}

{% block content %}
<form method="post" action=".">
  {% csrf_token %} 
  {{ form.as_p }}

  <input type="submit" value="{% trans 'Log in' %}" />
  <input type="hidden" name="next" value="{{ next }}" />
</form>

<p>{% trans "Forgot password" %}? <a href="{% url 'auth_password_reset' %}">{% trans "Reset it" %}</a>!</p>
<p>{% trans "Not member" %}? <a href="{% url 'registration_register' %}">{% trans "Register" %}</a>!</p>
{% endblock %}

如果我从模板文件夹中删除文件,使其为空,那么它能正常工作。希望我现在给您提供了一些有用的信息。


1
需要查看 allauth.urls 模块。 - wim
错误是在什么时候出现的?有堆栈跟踪吗? - e4c5
你是否正在使用allauth?如果是,为什么在你的模板中没有allauth代码,就好像你一直在不使用它。 你确定你的login.html文件在templates目录的“account”子目录中吗? - Jerzyk
1个回答

0
问题可能出在你的HTML代码中。尝试通过添加name='profile'来为该URL添加命名空间。请检查你的HTML代码,看看是否有类似于

的内容。
href="{% url 'YourApp:profile' %}"

你应该检查一下你的URL是否有ReverseMatch。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接