Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Django Security Checklist with manage.py check --deploy
📖 Scenario: You are preparing a Django web application for deployment. To ensure your app is secure, you want to use Django's built-in security checklist tool.This tool helps you find common security issues before going live.
🎯 Goal: Build a simple Django project setup and run the manage.py check --deploy command to identify security settings that need attention.
📋 What You'll Learn
Create a Django settings file with basic security settings
Add a variable to indicate debug mode
Use the manage.py check --deploy command to check security
Ensure the project is ready for deployment with recommended security settings
💡 Why This Matters
🌍 Real World
Before launching a Django website, developers use this checklist to avoid common security mistakes that could expose user data or allow attacks.
💼 Career
Knowing how to configure Django security settings and run deployment checks is essential for web developers and DevOps engineers to ensure safe production environments.
Progress0 / 4 steps
1
Create basic Django settings with security keys
Create a file named settings.py and add a variable SECRET_KEY with the value 'django-insecure-12345' and a variable DEBUG set to True.
Django
Hint
The SECRET_KEY is a string that Django uses for cryptographic signing. DEBUG should be True during development.
2
Add allowed hosts configuration
In settings.py, add a variable ALLOWED_HOSTS and set it to a list containing 'localhost' and '127.0.0.1'.
Django
Hint
ALLOWED_HOSTS tells Django which host/domain names your app can serve. This helps prevent HTTP Host header attacks.
3
Add security middleware to settings
In settings.py, add a variable MIDDLEWARE as a list containing the string 'django.middleware.security.SecurityMiddleware' as the first item.
Django
Hint
SecurityMiddleware helps manage security headers and HTTPS redirects.
4
Run the security check command
Run the command python manage.py check --deploy in your terminal to see the security checklist results for your current settings.
Django
Hint
This command checks your settings for common security issues before deployment.
Practice
(1/5)
1. What is the main purpose of running manage.py check --deploy in a Django project?
easy
A. To create a new database migration
B. To start the Django development server
C. To find security issues before deploying the site to production
D. To install required Python packages
Solution
Step 1: Understand the command's role
manage.py check --deploy runs checks specifically for security and deployment readiness.
Step 2: Compare with other commands
Other commands like migrations or server start do not check security issues.
Final Answer:
To find security issues before deploying the site to production -> Option C
Quick Check:
Security check = B [OK]
Hint: Remember: --deploy means check for production security [OK]
Common Mistakes:
Confusing it with migration commands
Thinking it starts the server
Assuming it installs packages
2. Which of the following is the correct way to run the security deployment check in Django?
easy
A. python manage.py startapp --deploy
B. python manage.py migrate --deploy
C. python manage.py runserver --deploy
D. python manage.py check --deploy
Solution
Step 1: Identify the correct command syntax
The command to check security issues is python manage.py check --deploy.
Step 2: Eliminate incorrect options
Other commands like migrate, runserver, or startapp do not accept --deploy and serve different purposes.
Final Answer:
python manage.py check --deploy -> Option D
Quick Check:
Correct command syntax = A [OK]
Hint: Use 'check' command with --deploy flag for security checks [OK]
Common Mistakes:
Using migrate or runserver with --deploy
Mixing up command names
Omitting 'python' or 'manage.py'
3. After running python manage.py check --deploy, you see a warning about SECURE_SSL_REDIRECT not being set. What will happen if you ignore this warning?
medium
A. Your site will not redirect HTTP requests to HTTPS, risking insecure connections
B. Your database migrations will fail
C. Your static files will not load
D. Your admin login page will be disabled
Solution
Step 1: Understand the warning about SECURE_SSL_REDIRECT
This setting forces HTTP requests to redirect to HTTPS, securing data in transit.
Step 2: Consequences of ignoring the warning
If not set, users can connect over insecure HTTP, exposing sensitive data.
Final Answer:
Your site will not redirect HTTP requests to HTTPS, risking insecure connections -> Option A
4. You ran python manage.py check --deploy and got this error: "Your SECRET_KEY is not set or is insecure." What is the best way to fix this?
medium
A. Set a long, random SECRET_KEY in your settings and keep it secret
B. Remove the SECRET_KEY setting from your settings file
C. Set SECRET_KEY to 'django-insecure' for simplicity
D. Ignore the warning; it only affects development
Solution
Step 1: Understand SECRET_KEY importance
SECRET_KEY is used for cryptographic signing and must be unique and secret.
Step 2: Fix by setting a strong, random key
Generate a long random string and set it in settings securely; do not share it.
Final Answer:
Set a long, random SECRET_KEY in your settings and keep it secret -> Option A
Quick Check:
Strong SECRET_KEY = A [OK]
Hint: Never share SECRET_KEY; generate a strong random one [OK]
Common Mistakes:
Using default insecure keys
Removing SECRET_KEY setting
Ignoring warnings thinking they're only for dev
5. You want to ensure your Django app is secure for production. Which combination of settings should you verify or enable after running manage.py check --deploy?
hard
A. Remove ALLOWED_HOSTS, set DEBUG=True, and disable security middleware
B. Set SECURE_SSL_REDIRECT=True, SESSION_COOKIE_SECURE=True, and DEBUG=False
C. Set DEBUG=True, ALLOWED_HOSTS=['*'], and CSRF_COOKIE_SECURE=False
D. Keep DEBUG=True, set SECURE_HSTS_SECONDS=0, and disable SSL redirect
Solution
Step 1: Identify secure production settings
SECURE_SSL_REDIRECT and SESSION_COOKIE_SECURE enforce HTTPS and secure cookies; DEBUG must be False in production.
Step 2: Eliminate insecure options
Options with DEBUG=True or ALLOWED_HOSTS=['*'] are insecure and should be avoided.
Final Answer:
Set SECURE_SSL_REDIRECT=True, SESSION_COOKIE_SECURE=True, and DEBUG=False -> Option B
Quick Check:
Secure settings = C [OK]
Hint: Disable DEBUG and enable SSL redirect for production [OK]