Configuring our project for SSL

Django comes with specific settings for SSL support. Edit the settings/pro.py settings file and add the following settings to it:

SECURE_SSL_REDIRECT = TrueCSRF_COOKIE_SECURE = True

These settings are as follows:

  • SECURE_SSL_REDIRECT: Whether HTTP requests have to be redirected to HTTPS
  • CSRF_COOKIE_SECURE: Has to be set for establishing a secure cookie for the cross-site request forgery protection

Congratulations! You have configured a production environment that will offer great performance for serving your project.

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.