[Answered ]-Django user authentication error

2👍

authenticate only verifies that username and password are correct and returns User instance found for that pair. To actually log user in and have it available in templates, sessions etc you need to call login

login(request, user)

0👍

short answer: use the built-in authentication. Don’t try to write youu own. https://docs.djangoproject.com/en/dev/topics/auth/

  • your code is totally broken – in the login view the variables uname and pwd are undefined. please post working code.
  • you seem to be doing authentication yourself – why don’t you just use the built in authentication methods?
  • it looks like part of your problem is that you defining a logged-in user with the variable user but that only exists in the scope of the function logon – the rest of your code is checking request.user. This is why you need to use the built in authentication methods.

Leave a comment