Using mixins from django-braces

django-braces is a third-party module that contains a collection of generic mixins for Django. These mixins provide additional features for class-based views. You can see a list of all mixins provided by django-braces at https://django-braces.readthedocs.io/.

We will use the following mixins of django-braces:

  • CsrfExemptMixin: To avoid checking the CSRF token in the POST requests. We need this to perform AJAX POST requests without having to generate a csrf_token.
  • JsonRequestResponseMixin: Parses the request data as JSON and also serializes the response as JSON and returns an HTTP response with the application/json content type.

Install django-braces via pip using the following command:

pip install django-braces==1.13.0 ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.