views:

144

answers:

1

Hello

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 redirects 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.

A: 

You must return the HttpResponse object:

return HttpResponseRedirect('/profile/')
jholster
I know i wrote HttpResponseRedirect in my question without return in front of it, but in my code it had return. Guess i had typo somewhere else... a typo that did not raise an error though? Strange.. ohwell...
Zayatzz
Strange indeed, an error should have been raised if no HttpResponse was returned from view function. Umm... I guess you have Session middleware enabled?
jholster
Well i did not paste whole view here. There was return render_to_response in the end of the view, so error because of no return was not raised. I think i did bunch of small things that summed up in strange behaviour. At least i think i've figured this out for myself :P
Zayatzz