如果下一个指向注销,则在登录到下一个后重定向

时间:2014-11-20 18:32:58

标签: django

django有优雅的方式将(在某些操作之后,例如login)重定向到上一页:

<a href="{% url 'login' %}?next={{ request.path }}">{% trans 'sign in' %}</a>
除非前一页恰好是logout页面,否则

的工作方式绝对正常。

有没有办法为next实现更高级的逻辑?如下

if next is 'logout' or 'something_else':
    redirect to constant path
else:
    redirect to the previous location
谢谢你!

1 个答案:

答案 0 :(得分:1)

如果您当前在退出页面上,如果更容易从模板中删除next参数:

{% if not "logout" in request.path %}?next={{ request.path }}{% endif %}
相关问题