What is django-userena?
django-userena is a Django application that supplies your Django project with full account management. It’s a fully customizable application that takes care of the signup, activation, messaging and more.
How to install django-userena?
You can install the latest version of django-userena using:
pip install django-userena
Source Code:
https://github.com/bread-and-pepper/django-userena
How to setup django-userena?
Add AUTHETICATION_BACKEND tuple as given below:
AUTHENTICATION_BACKENDS = (
'userena.backends.UserenaAuthenticationBackend',
'guardian.backends.ObjectPermissionBackend',
'django.contrib.auth.backends.ModelBackend',
)
Add userena, gaurdian and easy_thumbnails to your INSTALLED_APPS settings of your project.
The URI’s
Userena has a URLConf that sets all the url’s and views for you. This should be included in your project’s URLConf. For example, if you wants the urls to show up under ‘/accounts/’, add the following under urlpattern in you URLConf.
(r'^accounts/', include('userena.urls')),
Required Settings
1. Django-guardian requires you to set the ANONYMOUS_USER_ID setting.
ANONYMOUS_USER_ID = -1
2. Set AUTH_PROFILE_MODULE point to the model that is your custom made profile.For example: set AUTH_PROFILE_MODULE to the path of MyProfile
from userena.models import UserenaBaseProfile
class MyProfile(UserenaBaseProfile):
user = models.OneToOneField(User,
unique=True,
verbose_name=_('user'),
related_name='my_profile')
favourite_snack = models.CharField(_('favourite snack'),
max_length=5)
3. To integrate with Django, you need to alter three settings to reflect in you URI.
For example, if your userena lives under ‘/accounts/’
LOGIN_REDIRECT_URL = '/accounts/%(username)s/' LOGIN_URL = '/accounts/signin/' LOGOUT_URL = '/accounts/signout/'
References:django-userena documentation