Deploy Django
1. Prepare Your Project
Ensure you have a requirements.txt:
pip freeze > requirements.txtYour project should include gunicorn:
pip install gunicorn
pip freeze > requirements.txt2. Initialize
cd my-django-app
espacetech initespacetech.json
{
"name": "my-django-app",
"framework": "django",
"build_command": "pip install -r requirements.txt && python manage.py collectstatic --noinput",
"start_command": "gunicorn myproject.wsgi:application --bind 0.0.0.0:8000",
"port": 8000
}3. Configure Settings
settings.py
import os
# Allow your Espace-Tech Cloud domain
ALLOWED_HOSTS = [
"my-django-app.app.espace-tech.com",
"localhost",
os.environ.get("ALLOWED_HOST", "*"),
]
# Database from environment
import dj_database_url
DATABASES = {
"default": dj_database_url.config(
default=os.environ.get("DATABASE_URL", "sqlite:///db.sqlite3")
)
}
# Static files
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")4. Deploy
espacetech deployAdd PostgreSQL
espacetech db create django-db
espacetech db link django-db --project my-django-app
espacetech deployThe DATABASE_URL environment variable is injected automatically. Use dj-database-url to parse it.