python - how to use User class in Django -


i wrote user-login function, not work

this models.py

class userprofile(models.model):     userinfo = models.onetoonefield(user)     join_time = models.datetimefield()      def __unicode__(self):         return self.userinfo.username 

and userlogin in views.py

def userlogin(request):     uf = userform(request.post)     if request.method == "post":         if uf.is_valid():             uf = userform(request.post)             username = uf.cleaned_data['username']             password = uf.cleaned_data['password']             user = models.userprofile.authenticate(                 username=username,password=password)             if user not none:                 if user.is_active:                     login(request, user)                     return render(request,                         'userlogin/index.html',{'username':username})             else:                 return httpresponse('password not matched')     return render(request, 'userlogin/login.html',{'uf':uf}) 

i read document of django many times think didn't understand. way of using user model correct? confusing..

the reason reassignning value of form after validate it. when mas is_valid(), if is, able access cleaned data, not before. try change commenting recond uf assignation:

def userlogin(request):     uf = userform(request.post)     if request.method == "post":         if uf.is_valid():             #uf = userform(request.post)             username = uf.cleaned_data['username']             password = uf.cleaned_data['password'] 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -