Python Django Hosting Guide 2026
Complete guide to choosing the right hosting for your Django applications
Django is a powerful web framework for building web applications with Python — but choosing the right hosting is equally important. Not all standard web hosting services (PHP hosting) properly support Python and Django. This comprehensive guide will help you understand how to select the right hosting, install and configure Django properly, and deploy your application successfully to production.
Table of Contents
- What is Python/Django Hosting
- Server Requirements for Django
- Shared Hosting vs VPS vs Cloud
- How to Install Python and Django
- Gunicorn + Nginx Setup
- Virtual Environment and Requirements
- Deploy Django from GitHub
- Static/Media Files and Production Settings
- PostgreSQL Database Setup
- FAQ about Django Hosting
What is Python/Django Hosting and How is it Different from PHP Hosting?
PHP hosting is designed to directly support PHP code — typically, Apache or Nginx reads .php files and processes the code automatically. Django, however, works completely differently.
A Django application is a long-running process that requires an application server like Gunicorn or uWSGI to handle user requests. Nginx acts as a reverse proxy, forwarding requests to the Gunicorn process running in the background.
The key differences are:
- PHP Hosting: Apache/Nginx reads .php files directly → processes → returns result. Simple, suitable for small websites.
- Django Hosting: Requires Python runtime + Gunicorn/uWSGI application server + Nginx reverse proxy + PostgreSQL/MySQL database. More complex but better for large applications.
Most standard web hosting providers in Asia are designed primarily for PHP. When you need Django, you'll need a VPS or cloud hosting that gives you full control over the Linux server.
Server Requirements for Django Applications
A Django application needs several components to run properly:
- Python Runtime: Python 3.8+ (currently Python 3.11 or 3.12 is standard)
- pip Package Manager: To install Django and libraries
- Virtual Environment: venv — to isolate project dependencies
- Application Server: Gunicorn or uWSGI — to run the Django app
- Web Server: Nginx — to act as reverse proxy
- Database: PostgreSQL or MySQL — for your Django ORM
- SSL Certificate: HTTPS support (essential nowadays)
- Process Manager: Supervisor or Systemd — to keep Gunicorn running continuously
A server suitable for Django should have at least 512 MB to 1 GB of RAM for small applications, and 2 GB or more for medium to large applications. CPU is typically less of a bottleneck than RAM.
Shared Hosting vs VPS vs Cloud for Django
When choosing hosting for Django, consider these three main options:
1. Shared Hosting — Most shared hosting providers don't support Django. Even when they do, there are severe restrictions — you can't install new Python packages, no virtual environment support, and limited control. Not recommended.
2. VPS (Virtual Private Server) — You get full control over a Linux server. You can install Python, Gunicorn, Nginx exactly as you need. Ideal for developers with server management knowledge or team support. Pricing: approximately 200-500 THB/month (Thailand) or 500-1000 THB (Singapore).
3. Cloud Hosting (AWS, Google Cloud, DigitalOcean) — Highly flexible with auto-scaling capability but more expensive (starting 250-1000 THB/month). Best for applications with variable traffic or that need to scale frequently.
For beginners, a VPS in Thailand or Singapore is the best option — affordable pricing, sufficient for medium applications, and you can learn Linux administration alongside development.
How to Install Python and Django on VPS
Assuming you have a VPS running Ubuntu 22.04 LTS, follow these steps to install Python 3.11 and Django:
Step 1: Update server and install dependencies
sudo apt update
sudo apt upgrade -y
sudo apt install -y python3.11 python3.11-venv python3-pip build-essential libpq-dev
build-essential is needed to compile Python packages with C extensions. libpq-dev is essential for PostgreSQL integration.
Step 2: Verify Python version
python3.11 --version
pip3 --version
Step 3: Create project directory
mkdir -p /home/django
cd /home/django
sudo chown -R $USER:$USER /home/django
Step 4: Create virtual environment
python3.11 -m venv venv
source venv/bin/activate
Your prompt should now show (venv) user@server:/home/django$ — this confirms the virtual environment is active.
Step 5: Install Django
pip install --upgrade pip
pip install django gunicorn psycopg2-binary
Now create your Django project:
django-admin startproject mysite
cd mysite
python manage.py migrate
This creates essential files like manage.py, settings.py, urls.py, and wsgi.py.
Configuring Gunicorn + Nginx for Django Production
Next, configure Gunicorn to run your Django application and Nginx to act as a reverse proxy.
Step 1: Set up Gunicorn
First, test Gunicorn:
cd /home/django/mysite
source ../venv/bin/activate
gunicorn mysite.wsgi:application --bind 0.0.0.0:8000
If it works, create a Systemd service file for continuous operation:
sudo nano /etc/systemd/system/gunicorn.service
Add this content:
[Unit]
Description=Gunicorn Django Application
After=network.target
[Service]
User=www-data
WorkingDirectory=/home/django/mysite
ExecStart=/home/django/venv/bin/gunicorn mysite.wsgi:application --bind unix:/home/django/mysite/gunicorn.sock --workers 3
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
Save and enable the service:
sudo systemctl daemon-reload
sudo systemctl enable gunicorn
sudo systemctl start gunicorn
sudo systemctl status gunicorn
Step 2: Install and configure Nginx
Install Nginx:
sudo apt install -y nginx
Create Nginx configuration:
sudo nano /etc/nginx/sites-available/mysite
Add this configuration:
upstream django {
server unix:/home/django/mysite/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /home/django/mysite/static/;
}
location /media/ {
alias /home/django/mysite/media/;
}
location / {
proxy_pass http://django;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable the site:
sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Nginx now acts as a reverse proxy, forwarding HTTP requests to Gunicorn via Unix socket.
Virtual Environment and requirements.txt
A virtual environment is essential — it isolates your project's Python dependencies from the system Python. Benefits include:
- Prevents version conflicts between different projects
- Makes it easy to reproduce the environment on another server
- Simplifies deployment and updates
Creating requirements.txt:
pip freeze > requirements.txt
This saves all installed packages and their versions. Example requirements.txt:
Django==4.2.2
gunicorn==21.2.0
psycopg2-binary==2.9.7
Pillow==10.0.0
celery==5.3.1
redis==4.5.5
Installing from requirements.txt on a new server:
python3.11 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
This installs all packages with the exact same versions, ensuring consistent environments. Keep this file updated whenever you add or remove packages.
Deploying Django App from GitHub
Most Django projects are developed on GitHub. Deployment from GitHub should be automated as much as possible.
Step 1: Set up SSH key on server
Create a deployment SSH key:
ssh-keygen -t ed25519 -f /home/django/.ssh/deploy -C "deploy"
cat /home/django/.ssh/deploy.pub
Copy the public key and add it to GitHub repository settings → Deploy Keys.
Step 2: Clone repository
cd /home/django
git clone [email protected]:yourusername/mysite.git mysite
cd mysite
source ../venv/bin/activate
pip install -r requirements.txt
Step 3: Create deployment script
Create deploy.sh:
#!/bin/bash
cd /home/django/mysite
source ../venv/bin/activate
git pull origin main
pip install -r requirements.txt
python manage.py collectstatic --noinput
python manage.py migrate
sudo systemctl restart gunicorn
sudo systemctl restart nginx
echo "Deploy successful!"
Make it executable:
chmod +x deploy.sh
Step 4: GitHub Actions (Optional)
Create .github/workflows/deploy.yml in your repository for automated deployment:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy to VPS
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy
chmod 600 ~/.ssh/deploy
ssh -i ~/.ssh/deploy -o StrictHostKeyChecking=no [email protected] './deploy.sh'
This automates deployment every time you push to the main branch.
Static Files, Media Files and Django Settings for Production
During development, Django serves static files automatically. In production, Nginx should serve them directly.
Configure settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'
ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com']
DEBUG = False
SECRET_KEY = os.environ.get('SECRET_KEY', 'fallback-secret-key-not-for-production')
CSRF_TRUSTED_ORIGINS = ['https://yourdomain.com', 'https://www.yourdomain.com']
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
Collect static files:
python manage.py collectstatic --noinput
This command gathers all static files from every app into the STATIC_ROOT directory, where Nginx can serve them directly instead of going through Django.
For media files (user uploads), configure Nginx to serve them directly from the /media/ directory.
PostgreSQL Database for Django
Django supports SQLite, PostgreSQL, MySQL, and Oracle. For production, PostgreSQL is recommended for its performance and excellent tooling.
Step 1: Install PostgreSQL
sudo apt install -y postgresql postgresql-contrib
Step 2: Create database and user
sudo -u postgres psql
CREATE DATABASE mysite_db;
CREATE USER mysite_user WITH PASSWORD 'strong_password_here';
ALTER ROLE mysite_user SET client_encoding TO 'utf8';
ALTER ROLE mysite_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE mysite_user SET default_transaction_deferrable TO on;
GRANT ALL PRIVILEGES ON DATABASE mysite_db TO mysite_user;
\q
Step 3: Configure Django settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mysite_db',
'USER': 'mysite_user',
'PASSWORD': 'strong_password_here',
'HOST': 'localhost',
'PORT': '5432',
}
}
Step 4: Run migrations
python manage.py migrate
Django tables are now created in PostgreSQL. PostgreSQL advantages include:
- Excellent ACID transaction support
- Full-text search capabilities
- Native JSON data type
- Superior performance for large datasets
FAQ: Common Questions about Django Hosting
sudo apt install certbot python3-certbot-nginx. Then: sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com. Certbot automatically configures Nginx with HTTPS.