登录后重定向到django-registration-redux [英] Redirect back after login django-registration-redux
本文介绍了登录后重定向到django-registration-redux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从在html中看起来像这样:
{%urlauth_loginas login_url%}
{%如果login_url不在request.get_full_path%}
< li>
< form class =navbar-formmethod =POSTaction = {{login_url}}> {%csrf_token%}
< input type =textclass =form-控制顶栏name =usernameplaceholder =email/>
< input type =passwordclass =form-control top-barname =passwordplaceholder = {%transpassword%} />
< button type =submitclass =btn btn-default> {%trans登录%}< / button>
< / form>
< / li>
{%endif%}
我该怎么做?
解决方案
您可以使用下一个:
code>< form class =navbar-formmethod =POSTaction ={{login_url}}?next = {{request.path}}>
这将向您的表单添加一个GET请求,指向当前页面。
对于 request.path ,您必须在 settings.py
$ b $中定义模板上下文处理器b TEMPLATE_CONTEXT_PROCESSORS =(
django.core.context_processors.auth,
django.core.context_processors.debug,
django.core.context_processors.i18n,
django.core.context_processors.media,
django.core.context_processors.request,
)
I am using django-registration-redux and i have a login form in my navbar. I would like to stay on the same page after login. ie. if i am at mypage.com/polls/example after login i want to be back on mypage.com/polls/example not on url set in settings.
Login from in html looks like this:
{% url "auth_login" as login_url %}
{% if login_url not in request.get_full_path %}
<li>
<form class="navbar-form" method="POST" action={{ login_url }}>{% csrf_token %}
<input type="text" class="form-control top-bar" name="username" placeholder="email" />
<input type="password" class="form-control top-bar" name="password" placeholder={% trans "password" %} />
<button type="submit" class="btn btn-default">{% trans "Login" %}</button>
</form>
</li>
{% endif %}
How do i do that?
解决方案
You could use next :
<form class="navbar-form" method="POST" action="{{ login_url }}?next={{request.path}}">
This will add a GET request to your form that points back to the current page.
For request.path to work you have to define template context processors in your settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
)
这篇关于登录后重定向到django-registration-redux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文