Django @login_required'next'不正确的重定向 [英] Django @login_required 'next' incorrect redirect

查看:1450
本文介绍了Django @login_required'next'不正确的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是 @login_required 重定向到root页面而不是正确的下一个路径。
/ accounts / login /?next = / main / setka / 重定向到'/'而不是



有人可以帮助我吗?



代码:



头部URL

  url(r'^ main /',include('main.urls')),
url(r'^ accounts /',include('loginsystem.urls')),

loginsystem.urls

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

/ main / urls.py

 (r'^ setka / $',views.setka),

我链接到装饰器在'/'主页的相应视图

 < li>< a href =/ main / setka /> Setka< / a>< / li> 

loginsystem.views

 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $¬$ > 

login.html包含

  {%load staticfiles%} 

< link rel =stylesheettype =text / csshref ={%static'accounts / style.css'%}/>

{%if form.errors%}
< p class =error>抱歉无效< / p>
{%endif%}
< body>
< form action =/ accounts / auth /method =post> {%csrf_token%}
< label for =username>用户名:< / label>
< input type =textname =usernamevalue =id =username>
< label for =password> password:< / label>
< input type =passwordname =passwordvalue =id =password>

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

< / form>
< / body>

Url chain喜欢这样:'root /' - > root / accounts / login /?next = main / setka / - >'/'而不是'root / main / setka /'



任何建议将不胜感激。



具体来说,我想动态地将next路径附加到根地址,但根本不附加next路径。

解决方案

简单来说,您需要更改 LOGIN_URL LOGIN_REDIRECT_URL settings.py 中所需的路径。



例如:

  LOGIN_URL ='/ login /'
LOGIN_REDIRECT_URL ='/ user / accounts /'
pre>

My problem is that @login_required redirects to root page instead of correct next path. /accounts/login/?next=/main/setka/ redirects to '/' instead of /main/setka/ after logging in.

Could anybody assist me?

The code:

Head urls

url(r'^main/', include('main.urls')),   
url(r'^accounts/',include('loginsystem.urls')),

loginsystem.urls

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

/main/ urls.py

(r'^setka/$', views.setka),

my link to the corresponding view with the decorator at '/' homepage

<li><a href="/main/setka/">Setka</a></li>

loginsystem.views

@login_required
def setka(request):
    return render_to_response('main/setka.html')

login.html includes

    {% load staticfiles %}

<link rel="stylesheet" type="text/css" href="{% static 'accounts/style.css' %}" />

{% if form.errors %}
<p class="error">Sorry invalid</p>
{% endif %}
<body>
<form action="/accounts/auth/" method="post"> {% csrf_token %}
<label for="username">User name:</label>
<input type="text" name="username" value="" id="username">
<label for="password">password:</label>
<input type="password" name="password" value="" id="password">

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

</form>
</body>

Url chain likes this: 'root/' -> root/accounts/login/?next=/main/setka/ -> '/' instead of 'root/main/setka/'

Any suggestions would be much appreciated.

To be specific, I want to dynamically attach 'next' path to root address, but it does not attach 'next' path at all.

解决方案

Simple, you need to change the LOGIN_URL and LOGIN_REDIRECT_URL to your desired path in settings.py.

For example:

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/user/accounts/'

这篇关于Django @login_required'next'不正确的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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