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
谢谢你!
答案 0 :(得分:1)
如果您当前在退出页面上,如果更容易从模板中删除next
参数:
{% if not "logout" in request.path %}?next={{ request.path }}{% endif %}