开发者

django manual login and redirect

开发者 https://www.devze.com 2022-12-25 05:22 出处:网络
I have such view that handles user registration. After creating new user i want to manually authenticate it and log it in.:

I have such view that handles user registration. After creating new user i want to manually authenticate it and log it in.:

def register(request):
    ...

    ...
    if form.is_valid():
        username = form.cleaned_data['username']
        password = form.cleaned_data['password1']
        email = ''
        newuser = User.objects.create_user(username, email, password)
        user = authenticate(username=username, password=password)
        login (request, user)

I have set LOGIN_REDIRECT_URL to '/profile/', but after authenticating and logging user in, it redir开发者_运维百科ects me back to the same view not to /profile/, why? And how can i specify where to redirect after logging in? If i add

HttpResponseRedirect('/profile/')

After login line - nothing happens. The script never ends up there.

Alan.


You must return the HttpResponse object:

return HttpResponseRedirect('/profile/')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号