我在我的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 %}
如果我从模板文件夹中删除文件,使其为空,那么它能正常工作。希望我现在给您提供了一些有用的信息。
allauth.urls
模块。 - wim