设置.py
AUTH_USER_MODEL = "app_registration.MyUser"
AUTH_PROFILE_MODULE = 'app_registration.MyUserProfile'
模型.py
class MyUserProfile(models.Model):
user = models.ForeignKey(MyUser, unique=True)
...
MyUser.profile = property(lambda u: MyUserProfile.objects.get_or_create(user=u)[0])
login.html
<form id="login_form" method="post" action=".">
....
<input type="hidden" name="next" value="" />
<input type="submit" value="LogIn" />
</form>
所以我这样做是为了为我的自定义 MyUser 模型创建 MyUserProfile 模型。
一切正常,除了当我登录(localhost/accounts/login)时,url 被重定向到
htp://localhost:9999/accounts/profile
而不是我在表单的隐藏输入中指定的索引页。这个重定向 url 在哪里定义..??
最佳答案
使用 LOGIN_REDIRECT_URL :
LOGIN_REDIRECT_URL
Default: '/accounts/profile/'
The URL where requests are redirected after login when the contrib.auth.login view gets no next parameter.
This is used by the login_required() decorator, for example.
关于python - Django 的 AUTH_PROFILE_MODULE 更改登录成功 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18009090/