A simple django authentication app using class-based-views.
[x] Configure with django settings
[x] Custom User django
[x] Register, Login and Logout
[ ] Email registration confirmation link
[ ] Password reset
-
Install app in project:
pip install git+https://github.com/jgmartinss/django-accounts-cbv
-
Add
accounts
toINSTALLED_APPS
in settings file:# settings.py INSTALLED_APPS = ( # ... 'accounts', )
-
Add these lines to your URL configuration, urls.py:
# urls.py urlpatterns = ( # ... path('accounts/', include('accounts.urls')), )
-
Create your or edit User template if desired:
# models.py class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField(_('Email'), max_length=255, unique=True) nickname = models.CharField(_('Nickname'), max_length=120, unique=True) first_name = models.CharField(_('Firt Name'), max_length=255) last_name = models.CharField(_('Last Name'), max_length=255) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) is_admin = models.BooleanField(default=False)
-
Add URL path in LoginView and LogoutView:
# views.py class LoginView(FormView): success_url = reverse_lazy('EXAMPLE:EXAMPLE') class LogoutView(LoginRequiredMixin, RedirectView): url = '/EXAMPLE/EXAMPLE/'
-
Configure django-accounts-cbv in your settings:
# settings.py AUTH_USER_MODEL = 'accounts.User' AUTHENTICATION_BACKENDS = ( ('django.contrib.auth.backends.ModelBackend'), )
-
Run the app and check it out:
$ python manage.py makemigrations accounts $ python manage.py migrate $ python manage.py runserver $ python manage.py createsuperuser