Learn how to deploy a Django project for production using the right settings, static files, a web server, and a hosting platform. This guide explains the full deployment process in simple steps for beginners.
Django's runserver command is only intended for local development and testing.
It should not be used in production environments.
A production Django deployment typically includes your application code, a WSGI or ASGI server, static file handling, environment variables, and a hosting platform or virtual server. Common tools include Gunicorn, WhiteNoise, PostgreSQL, Render, and PythonAnywhere.
Before deploying your Django project, make sure you have:
requirements.txt file containing all dependencies.DEBUG=False and proper ALLOWED_HOSTS.Before deployment, update your Django settings for production. Disable debug mode and configure allowed hosts.
DEBUG = False
ALLOWED_HOSTS = [
"yourdomain.com",
"your-app.onrender.com"
]
Store sensitive values such as SECRET_KEY and database credentials
in environment variables rather than hardcoding them into your project.
Most Django deployments use Gunicorn as the application server, WhiteNoise for serving static files, and PostgreSQL as the database.
Install the required packages:
pip install gunicorn whitenoise psycopg2-binary
Update your requirements file:
pip freeze > requirements.txt
Production servers do not automatically serve static files. Configure WhiteNoise and static file settings.
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
# Other middleware...
]
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
Collect static files:
python manage.py collectstatic --noinput
Apply migrations so the production database matches your Django models.
python manage.py migrate
If you are using PostgreSQL, configure your
DATABASE_URL environment variable.
Popular beginner-friendly deployment platforms include PythonAnywhere and Render.
Example Render build command:
pip install -r requirements.txt && \
python manage.py collectstatic --noinput && \
python manage.py migrate
Example start command:
gunicorn your_project_name.wsgi:application
Production deployments use a WSGI or ASGI server instead of Django's development server.
Common Gunicorn command:
gunicorn your_project_name.wsgi:application
Example ASGI deployment:
gunicorn your_project_name.asgi:application \
-k uvicorn.workers.UvicornWorker
Run Django's deployment checklist before going live.
python manage.py check --deploy
Also ensure that:
requirements.txt.DEBUG=False and configure ALLOWED_HOSTS.SECRET_KEY and DATABASE_URL.collectstatic and database migrations.What's next?
Apply your knowledge with one of our rigorous, hands-on internship programs.
Browse Internships