- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将用户重定向到包含他的用户名的网址(例如http://domain/username/),并试图弄清楚如何做到这一点。我正在使用django.contrib.auth进行用户管理,因此我尝试在设置中使用LOGIN_REDIRECT_URL:
LOGIN_REDIRECT_URL = '/%s/' % request.user.username # <--- fail..
最佳答案
一种解决方案是重定向到静态路由,例如“/userpage/”,然后将其重定向到最终的动态页面。
但是我认为真正的解决方案是创建一个新 View ,以实现您真正想要的功能。
from django.contrib.auth import authenticate, login
from django.http import HttpResponseRedirect
def my_view(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
HttpResponseRedirect('/%s/'%username)
else:
# Return a 'disabled account' error message
else:
# Return an 'invalid login' error message.
关于django LOGIN_REDIRECT_URL具有动态值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1608261/
我是 django 的新手,两周以来一直在努力实现身份验证。 当我从我的 /auth/login 页面成功登录时,我想被重定向到 /auth/logged_in。但是,它会将我重定向到 /auth/l
这是我在 settings.py 中的登录重定向 url: LOGIN_REDIRECT_URL='/category/all' 这是我的登录 View : def login(request):
我已经编写了自己的登录和注销 View 。 我正在使用 LOGIN_REDIRECT_URL 设置重定向页面。 我的登录 View 相当简单: def todologin(request):
我正在使用 django-alluth 进行社交登录。我关心的是如何登录到特定的 url 而不是 settings.py 文件中的固定 LOGIN_REDIRECT_URL? 当我尝试删除 LOGIN
站点的其余部分可以正常工作,但登录后的重定向是 http ://127.0.0.1:8443/after_login 不是预期的 https://127.0.0.1:8443/after_login
我是一名优秀的程序员,十分优秀!