Implementing Authentication in Django through AJAX Requests
Django by deffault provieds an excellent authentication functionality. It's integration is easy with minimal effort. But, most of the modern day websites demand AJAX calls rather than submitting the forms and reloading the page. This is important for a better "User Experience".
Also, the django auth by default supports username-password authentication and stores username as the primary key. The change from username to email-password authentication can sometimes be confusing for a complete Django-beginner.
I have created a library - Django AJAX Auth, for the same purpose.
link - Django AJAX Auth
This can directly be implemented with your existing code to support AJAX authentication with email-password authentication.
Steps to integrate
- Clone the project
git clone https://github.com/gauravkulkarni96/django-ajax-auth.git
- Copy the following lines to your project's
settings.py
.
LOGIN_REDIRECT_URL = '/'
AUTH_USER_MODEL = 'registration.User'
- Copy the
registration
app to your project folder. - Change the location of templates folder as required (as per settings).
- Run migrations
python manage.py makemigrations registration
python manage.py migrate