Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:40:27+00:00 2026-05-22T20:40:27+00:00

I want to log a user in with the following code: try: user =

  • 0

I want to log a user in with the following code:

try:
                user = User.objects.get(username = username)
                print "user found"

                if user.password == password and user.is_active:
                    print "user: " + str(user)
                    try:
                        print "test1"
                        login(request, user)
                        print "test2"
                    except:
                        print "error"
                        import sys
                        print "--> " + str(sys.exc_info()[0])
                        raise
                    user_is_valid = True
                    print "hell yeah!!"
            except:
                user = None
                print "failed"

What gives the following console output when logging in with a active user:

user found
user: testuser@email.com
test1
error
--> <type 'exceptions.AttributeError'>
failed

The usernames are email adresses but I see no problem with that. The user is active and as you can see is the user object not None. Why is the login method throwing the bad attribute exception and how can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:40:28+00:00Added an answer on May 22, 2026 at 8:40 pm

    Why are you doing any of this? First of all, you shouldn’t be catching the exception only to re-raise it. Running with DEBUG on, Django provides you with an excellent error page which would have shown you the actual error and the code that raises it – in particular, you would have seen which attribute is being accessed.

    Most likely, the error is that you haven’t called authenticate on the user, which as well as checking the password also adds an attribute recording which authentication backend authenticated that user. The documentation on how to log a user in is quite clear that you need to call this – note the box stating ‘calling authenticate first’.

    The third thing you should definitely not be doing is checking a password as text – Django stores them as hashes, so you need to compare the hashed value. Again, authenticate will take care of this for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user log into my asp.net site I use the following code: FormsAuthentication.RedirectFromLoginPage(userid,
I want to log user's actions in my Ruby on Rails application. So far,
I want to log my log strings to a file. I implemented the following
I want to pull posts from a users Facebook wall. The following code snippet
I have the following code. try { if (vm.SubmitAction == Cancel) return RedirectToAction(ShowSummary, new
I want to save logs of user's operation by accessing log script file(for example,
I am trying to run the following code, to assign user selected text in
i want log linenumber to my log file, using log4net.the config details of log4net
I want to log onto Stack Overflow using OpenID, but I thought I'd set
I want to log to the console when I'm using un-minimized JavaScript files. Comments

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.