1

I want to add the authentication functionality in my application. I have below code snippet:

user = User.objects.create_user('jkd')
user.set_password('space')
user.save
user = authenticate(username='jkd', password='space')
print "User:",user

It always prints the "User:None". I have also added below in my settings.py file:

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend', # default
     # any other authentication backends
)

I have gone through answers of same question in different thread but it doesn't help me.

3
  • 2
    Are you sure your user is actually getting created successfully? Also when saving the user don't you have to call user.save() instead of user.save? Commented Apr 21, 2017 at 5:35
  • Yes.After user.save I have put the print like: print user.It displays the user name that is added. Commented Apr 21, 2017 at 5:37
  • Thanks Georgina S.It helped me Commented Apr 21, 2017 at 5:46

1 Answer 1

1

There is typo in your code, thus the record has not been saved yet

Change from

user.save

to

user.save()
Sign up to request clarification or add additional context in comments.

2 Comments

Georgina S should have the credit as well, cos he gave you the hint first (I just realized about that). I didn't look at the comments when posting this answer though
Yes I have up voted her comment.Is there any other way by which i can give credit to her?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.