Skip to content

Django Security Best Practices

Secure your Django application against common vulnerabilities.

Django Security

Follow these practices to protect your Django application.

Essential Settings

# settings.py for production
DEBUG = False
ALLOWED_HOSTS = ['yourdomain.com']
SECURE_SSL_REDIRECT = True
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
SECURE_HSTS_SECONDS = 31536000

Additional Security

  • Use django-csp for Content Security Policy
  • Enable rate limiting
  • Validate all user input
{# Provenance for articles generated from a source document. Rendered here rather than stored in the body so it stays accurate and cannot be edited away, and so the sealed draft stays purely generated. #}

Discussion

0

No comments yet. Be the first to start the discussion!

Leave a Comment

Comments are reviewed before they appear.

Write a comment