When a user logs in to a Django app, how do I change the URL of the page that shows up after they log in?
I currently have the following view:
def users_login(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return HttpResponseRedirect("/start/")
I state that the app should redirect to domain.com/start/, but unfortunately, it does not. It instead goes to domain/login/, which is the location in the action attribute of the login form.
When I have the following code in my view:
return redirect('http://www.google.com/')
I get an error. I don’t understand why. It only happens with forms. After a user submits a form, the URL stays at the action attribute’s URL, even though the corresponding view has a redirect to a static page.
Eugene Soldatov is right,
but you should use built-in login view to make it work (you should use it anyway).