Codementor Events

Implementing Authentication in Django through AJAX Requests

Published May 28, 2018

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

  1. Clone the project
  git clone https://github.com/gauravkulkarni96/django-ajax-auth.git
  1. Copy the following lines to your project's settings.py.
  LOGIN_REDIRECT_URL = '/'
  AUTH_USER_MODEL = 'registration.User'
  1. Copy the registration app to your project folder.
  2. Change the location of templates folder as required (as per settings).
  3. Run migrations
  python manage.py makemigrations registration
  python manage.py migrate

QED 😄

Discover and read more posts from Gaurav Kulkarni
get started
post commentsBe the first to share your opinion
Show more replies