我在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 %}
因此,如果我从模板文件夹中删除文件,并让他为空,那么它可以正常工作。我希望我现在给你一些有用的信息。
答案 0 :(得分:0)
问题可能在于您的HTML。尝试通过添加name =&#39; profile&#39;来命名该网址。如果您有类似
的内容,请检查您的HTMLhref="{% url 'YourApp:profile' %}"
您应该检查您的网址是否有ReverseMatch。