Skip to Content

Deploy Django

1. Prepare Your Project

Ensure you have a requirements.txt:

pip freeze > requirements.txt

Your project should include gunicorn:

pip install gunicorn pip freeze > requirements.txt

2. Initialize

cd my-django-app ghayma init
.ghayma.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 Ghayma domain ALLOWED_HOSTS = [ "my-django-app.ghayma.app", "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

ghayma deploy

Add PostgreSQL

ghayma db create django-db --site main

--site main connects the database to your site (leave it out and, on a terminal, the command asks), so DATABASE_URL is derived for that site — the running app picks it up without a redeploy once the database accepts logins, usually within a minute, and every later deploy derives it again. Use dj-database-url to parse it. See Automatically injected variables.

Internal Networking: If your Django app connects to Ghayma services (Auth, databases, storage API), use internal URLs for deployed apps. See the Networking Guide.