Skip to content

HTTPS Support

Overview

HTTPS ensures secure communication over the network by encrypting data.

Django’s Protection Mechanisms

  • SECURE_SSL_REDIRECT: Redirect all HTTP requests to HTTPS.
  • SESSION_COOKIE_SECURE: Ensure cookies are only sent over HTTPS.
  • CSRF_COOKIE_SECURE: Ensure CSRF cookies are only sent over HTTPS.

Example

# settings.py
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

Best Practices

  • Obtain and install an SSL/TLS certificate.
  • Enable HTTPS settings in Django.
  • Regularly monitor and update your SSL/TLS configuration.