Problems with custom Auth Backends: 'NoneType' object has no attribute 'DoesNotExist'

883 views
Skip to first unread message

Sandra Django

unread,
Oct 8, 2009, 8:50:00 AM10/8/09
to django...@googlegroups.com

Hi, I want add a new attribute in User model and create custom backends. Steep by steep, I did the following:
1) I created an application named "profile" into my project
2) I created, in models.py of "profile" a class named "UserProfile", which
inherits from User class of Django. I added "press_agency" attribute, and I wrote objects = UserManager()
3) I registered UserProfile and UserProfileAdmin classes in admin.py, and unregistered User of Django.
4) Into my project, I created auth_backends.py file. You should see it here: http://dpaste.com/hold/101036/
5) In settings.py I wrote:
    AUTHENTICATION_BACKENDS = (
    'myproject.auth_backends.CustomUserModelBackend', )

   CUSTOM_USER_MODEL = 'myproject.profile.UserProfile'

Then, when I go to login, write mi name and password, y the system returns the following error:
'NoneType' object has no attribute 'DoesNotExist'
Why? What is the problem?

Shawn Milochik

unread,
Oct 9, 2009, 11:06:07 PM10/9/09
to django...@googlegroups.com
The way to do what you're trying to do is to take advantage of the following:


In brief, you'll create another model, which will then be specified in your settings.py by AUTH_PROFILE_MODULE. From then on, you will be able to use the contrib.auth.model.User  builtin function get_profile() to

Shawn Milochik

unread,
Oct 8, 2009, 9:53:32 AM10/8/09
to django...@googlegroups.com

http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

() to return your custom object.

You will not be subclassing the User model; there's no need, and it
greatly complicates things to try. I'm currently working on doing this
myself, because I am adding requirements for the password change.
Namely, I need the password to expire after 90 days, I need the
initial password to require a reset after the first successful login,
and I need to enforce some rules about the complexity and non-reuse of
the password.

Shawn

Reply all
Reply to author
Forward
0 new messages