django - 没有反向匹配的登录视图 [英] django - no reverse match for login view

查看:240
本文介绍了django - 没有反向匹配的登录视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



基本上我想看看用户登录表单页面,但我得到:

 渲染时捕获NoReverseMatch:反转为''django.contrib.auth.views.login'与参数'()'和关键字参数'{}'未找到。 

我的urls.py文件:

  from django.conf.urls.defaults import patterns,include,url 

urlpatterns = patterns('',
url(r'^ accounts / login / $','django.contrib.auth.views.login'),

我的settings.py(INSTALLED_APPS)

  INSTALLED_APPS =(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
' django.contrib.staticfiles',






<编辑:我意识到我在看错了事情。错误发生在模板文件中:

  {%if form.errors%} 
< p>您的用户名和密码不匹配。请再试一次。< / p>
{%endif%}

< form method =postaction ={%url'django.contrib.auth.views.login'%}>
{%csrf_token%}
< table>
< tr>
< td> {{form.username.label_tag}}< / td>
< td> {{form.username}}< / td>
< / tr>
< tr>
< td> {{form.password.label_tag}}< / td>
< td> {{form.password}}< / td>
< / tr>
< / table>

< input type =submitvalue =login/>
< input type =hiddenname =nextvalue ={{next}}/>
< / form>

专门针对这一行:

 < form method =postaction ={%url'django.contrib.auth.views.login'%}> 


解决方案

尝试这个:

  url(r'^ accounts / login $','django.contrib.auth.views.login'),

编辑后:

  form method =postaction ={%url django.contrib.auth.views.login%}> 

编辑
设置。 py django文件,此行:



APPEND_SLASH = False



告诉您的反向网址是否以斜线完成。然后

  APPEND_SLASH = True 
url(r'^ accounts / login /','django.contrib.auth。 views.login')

应该也可以。


I am just trying out django and following the documentation for authentication.

Basically I want to take a look at the user login form page, but I am getting:

Caught NoReverseMatch while rendering: Reverse for ''django.contrib.auth.views.login'' with arguments '()' and keyword arguments '{}' not found.

My urls.py file:

from django.conf.urls.defaults import patterns, include, url

urlpatterns = patterns('',
    url(r'^accounts/login/$', 'django.contrib.auth.views.login'),
)

My settings.py (INSTALLED_APPS)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)


EDIT: I realized I was looking at the wrong thing. The error occurs in the template file:

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
    <td>{{ form.username.label_tag }}</td>
    <td>{{ form.username }}</td>
</tr>
<tr>
    <td>{{ form.password.label_tag }}</td>
    <td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>

Specifically for the line:

<form method="post" action="{% url 'django.contrib.auth.views.login' %}">

解决方案

Try this:

url(r'^accounts/login$', 'django.contrib.auth.views.login'),

And after your edit:

<form method="post" action="{% url django.contrib.auth.views.login %}">

EDIT in settings.py file of django, this line:

APPEND_SLASH = False

tells whether your reverse url finish with slash or not. Then

APPEND_SLASH = True
url(r'^accounts/login/', 'django.contrib.auth.views.login')

should work as well.

这篇关于django - 没有反向匹配的登录视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆