render('django.contrib.auth.views.login')指向与{%url'django.contrib.auth.views.login'%}不同的url [英] render('django.contrib.auth.views.login') pointing to different url than {% url 'django.contrib.auth.views.login' %}

查看:174
本文介绍了render('django.contrib.auth.views.login')指向与{%url'django.contrib.auth.views.login'%}不同的url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Django 1.5.1上使用Django认证系统的默认实现。

I'm on Django 1.5.1 using the default implementation of the Django authentication system.

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.markup',
    'django.contrib.admindocs',
    'flowcharts',
    'south',
    'helpdesk',
)

以下是注册/登录中的模板:

Here is the template located in registration/login:

{% extends "base.html" %}

{% block content %}

{% 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>

{% endblock %}

在我的urls.py文件中:

and in my urls.py file:

urlpatterns = patterns('',
    url(r'^accounts/login/$', 'django.contrib.auth.views.login'),
    url(r'^accounts/logout/$', 'django.contrib.auth.views.logout' , {'next_page': '/accounts/login/'}),
)

表单动作映射到'/ helpdesk / login /'

The form action is mapping to '/helpdesk/login/'

但是当我在python shell中运行render('django.contrib.auth.views.login')时,我得到'/ accounts / login /',这是我想要的形式指向的URL。如果需要有关该项目的其他信息,请告诉我们。

But when I run render('django.contrib.auth.views.login') in the python shell I get '/accounts/login/' , which is the URL that I want the form pointing to. Let me know if any other information is needed about the project.

推荐答案

您要使用django身份验证系统:

You want to use django authentication system:

在您的urls.py:

Have this in your urls.py:

urlpatterns = patterns('',
    url(r'^accounts/', include('django.contrib.auth.urls'))
)

在您的注册/login.html:

In your registration/login.html:

<form method="post" action="{% url login %}">

您想在注销中提供next_url,所以每当您想要呼叫退出时:

You want to provide a next_url in the logout, so whenever you want to call logout:

<a href="{% url logout %}?next=/accounts/login/">Logout</a>

检查您指出的链接的第191行。他们将 / helpdesk / login / 命名为登录,因此您的 {%url login%} 指向 / helpdesk / login

Check line 191 of the link you pointed. They name /helpdesk/login/ as login and so your {% url login %} points to /helpdesk/login.

您必须具有 url(r'^ helpdesk /',include('helpdesk.urls')) before url(r'^ accounts /',include('django.contrib。 auth.urls')) urls.py 中。改变这两个网址的顺序。

You must be having url(r'^helpdesk/', include('helpdesk.urls')) before url(r'^accounts/', include('django.contrib.auth.urls')) in your urls.py. Change the order of these two urls.

这篇关于render('django.contrib.auth.views.login')指向与{%url'django.contrib.auth.views.login'%}不同的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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