如何配置在 Django 中注销后重定向的位置? [英] How to configure where to redirect after a log out in Django?

查看:24
本文介绍了如何配置在 Django 中注销后重定向的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道我可以在哪里设置注销后重定向到的 url.我知道您可以设置登录网址.我想重定向到我的主页.

Just wondering where I can set the url to redirect to after logout. I know you can set the login url. I want to redirect to my home page.

推荐答案

Modern Django (2017+?) 有一个名为 LOGOUT_REDIRECT_URL 的设置.

Modern Django (2017+?) has a setting called LOGOUT_REDIRECT_URL.

您不需要覆盖或包装任何东西.

You don't need to overwrite or wrap anything.

根据文档,您可以只向注销视图提供 next_page 参数.https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.views.logout

According to the docs, you can just supply the next_page argument to the logout view. https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.views.logout

(r'^logout/$', 'django.contrib.auth.views.logout',
                          {'next_page': '/successfully_logged_out/'})

这篇关于如何配置在 Django 中注销后重定向的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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