Django登录没有更改URL



我使用简单的Django URL登录用户并发送到所需的页面,但作为用户登录URL不会更改。

Views.py

from django.contrib.auth import authenticate, login
def my_view(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return render(request, 'required.html')

URL没有改变,它仍然是http://127.0.0.1:8000/myApp/login/

如何更改URL?

当然,当你返回渲染结果时,它不会重定向,所以用重定向代替你的返回

return redirect('home') #where home is a name for a view

最新更新