python - NoReverseMatch 在/accounts/signup/django-allauth 错误

标签 python django django-allauth

我的 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 %}

因此,如果我从我的模板文件夹中删除文件,并让他为空,它就可以正常工作。我希望我现在给了你一些有用的信息。

最佳答案

问题可能出在您的 HTML 中。尝试通过添加 name='profile' 为该 url 命名空间。如果您有类似

的内容,请检查您的 HTML
href="{% url 'YourApp:profile' %}"

您应该检查您的网址是否有反向匹配。

关于python - NoReverseMatch 在/accounts/signup/django-allauth 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37307456/

相关文章:

python - 具有多种共同属性的多种类型的用户

python - 如何将 django 模型对象和相关对象转换为字典列表?

python - 我如何从 django-allauth 中的陈旧 token 生成新的访问 token ?

python - 几天不活动后,Django Allauth 似乎将用户注销

python - 使用 django-allauth 启用 oauth 登录,但使用自定义提供程序

python - 在输出和目标标签之间使用 nn.Cross entropy

python - np.random.multivariate_normal 的混淆行为

Python:用高斯上升和指数衰减拟合数据

django - 将第二个注册屏幕添加到社交注册 allauth

python - 我的脚本无法单击某个网格