Django - 登录后,将用户重定向到他的自定义页面 - > mysite.com/username [英] Django - after login, redirect user to his custom page --> mysite.com/username

查看:127
本文介绍了Django - 登录后,将用户重定向到他的自定义页面 - > mysite.com/username的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,登录后django将用户重定向到帐户/配置文件页面,或者如果您编辑LOGIN_REDIRECT_URL,您可以将用户发送到settings.py中指定的其他页面。

By default after login django redirects the user to an accounts/profile page or if you edit the LOGIN_REDIRECT_URL you can send the user to another page you specify in the settings.py.

这是非常好的,但我希望用户(登录后)被重定向到自定义页面,其中该页面的链接将如下所示: mysite.com/username 。因此,默认帐户/配置文件或LOGIN_REDIRECT_URL设置在这种情况下将不起作用,因为这两者都是静态的。在我的情况下,每个用户的地址的用户名部分更改。

This is great but I would like the user (after login) to be redirected to a custom page where the link to that page would look something like this: mysite.com/username. So the default accounts/profile or the LOGIN_REDIRECT_URL settings would not work in this case since both are somehow static. In my case the username section of the address changes for every user.

任何想法如何在用户登录时可以这样做,将转到在地址中具有用户名的自定义用户页面,如: mysite.com/username ?任何输入都是真正的赞赏。

Any ideas how I can make it so when the user is logged in would go to a custom user page that has user's name in the address like: mysite.com/username ? Any input is truly appreciated.

推荐答案

您可以按照以下说明对用户进行身份验证和登录: http://docs.djangoproject.com/en/dev/topics/auth/#how- to-log-a-user-in

You can authenticate and log the user in as stated here: http://docs.djangoproject.com/en/dev/topics/auth/#how-to-log-a-user-in

这将允许您访问User对象,您可以从中获取用户名,然后执行HttpResponseRedirect到自定义网址。

This will give you access to the User object from which you can get the username and then do a HttpResponseRedirect to the custom URL.

这篇关于Django - 登录后,将用户重定向到他的自定义页面 - > mysite.com/username的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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