这是我在settings.py中的登录重定向url:
LOGIN_REDIRECT_URL='/category/all'
这是我的登录视图:
def login(request):
if request.user.is_authenticated:
return redirect('/')
else:
if request.method == "POST":
email=request.POST['email']
password=request.POST['password']
user=auth.authenticate(email=email,password=password)
if user is not None:
auth.login(request, user)
return redirect('/')
else:
messages.info(request,"Email Password didn't match")
return redirect('login')
else:
return render(request,"login.html")
每当用户登录时,我都想将他重定向到类别/all页面,但它总是重定向到索引(“/”),这可能是因为我使用的是返回重定向(“/”).Also,即使当我有某些视图所需的登录时,即使url是这样的:
http://localhost:8000/login/?next=/cart/
不是将我重定向到购物车,而是重定向太索引。请帮我解决这个问题,这样重定向才能正常工作。
发布于 2020-08-20 18:50:11
在代码中,您使用的是返回重定向(‘/’)语句,它将您重定向到主页。
要处理像这样的url的重定向- http://localhost:8000/login/?next=/cart/,您需要从url中获得下一个参数的值,然后编写类似这样的语句。(在使用“返回重定向(‘/’)”语句时添加此语句)
next = request.GET.get('next')如果next:返回重定向(Next),否则:返回重定向(‘/’)
对不起,格式不正确,我是从移动发帖。
https://stackoverflow.com/questions/63511158
复制相似问题