python - Django user login after creation isn't working -
i using django auth framework user registration, , log user in right away. here's code:
class signupview(formmixin, processformview): http_method_names = ['post'] form_class = usercreationform success_url = reverse_lazy('default_page') def form_valid(self, form): if form.cleaned_data['is_usertype_1']: self.success_url = reverse_lazy('some_page') form.save() user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1']) if user none: raise exception("could not authenticate new user") login(self.request, user) homecoming super(signupview, self).form_valid(form) def form_invalid(self, form): pass
basically, have extended usercreationform
add together is_usertype_1
field, , displaying booleanfield
. , using data, determining user gets redirected after signup.
but problem arises when seek log created user in. no exception gets raised, reason, subsequent redirects still holds anonymoususer
in request.user. when log in created user manually, login works fine. doing wrong here?
thanks help in advance.
it turns out it's same issue django automatic login after user registration (1.4)
following import statement:
from django.contrib.auth import forms auth_forms, views auth_views, login, authenticate
changed to
from django.contrib.auth import forms auth_forms, views auth_views django.contrib.auth import login auth_login, authenticate auth_authenticate
and updated login
, authenticate
phone call auth_login
, auth_authenticate
, seems work now.
thank help !
python django django-authentication
No comments:
Post a Comment