Run a Python app (Django, Flask)
The Node.js and Python apps card in Developer runs Flask, Django, and other WSGI apps behind your domain. It creates an isolated virtual environment for each app.
Before you start
- A domain or subdomain. See Create a subdomain.
- Your project, with a
requirements.txt. - Know the limits. See Resource limits explained.
Create the app
- Open Account → Hosting → your site → Developer.
- Under Node.js and Python apps, click New app.
- Fill in:
| Field | Example |
|---|---|
| Runtime | Python |
| Python version | The newest 3.x on the list (3.13 at the time of writing) |
| Address | app.example.ca, with a path if you want one |
| Code folder | apps/bakery |
| Startup file | passenger_wsgi.py |
- Click Create app.
Passenger looks for a callable named application in the startup file. The examples below define it.
Flask example
~/apps/bakery/app.py:
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def home():
return jsonify(ok=True, shop="North Shore Bakery")
@app.route("/health")
def health():
return "ok"
~/apps/bakery/passenger_wsgi.py:
# Passenger looks for a WSGI callable named "application".
from app import app as application
requirements.txt:
Flask==3.0.3
gunicorn==22.0.0
Django example
passenger_wsgi.py:
import os
import sys
# Make the project importable
sys.path.insert(0, os.path.dirname(__file__))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bakery.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
In settings.py:
import os
DEBUG = False
ALLOWED_HOSTS = ["app.example.ca"]
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
STATIC_ROOT = "/home/yourusername/public_html/static"
STATIC_URL = "/static/"
Run these over SSH to collect static files and set up the database:
source /home/yourusername/virtualenv/apps/bakery/3.12/bin/activate && cd /home/yourusername/apps/bakery
python manage.py collectstatic --noinput
python manage.py migrate
Your app's virtual environment lives under ~/virtualenv/. Check the folder for the exact path and Python version.
Install requirements
- Put
requirements.txtin your code folder. - In Developer, find your app under Node.js and Python apps and click Install packages.
- Click Restart.
Or in SSH: pip install -r requirements.txt.
Set environment variables
The Developer section doesn't have a screen for app variables yet. Keep values such as DJANGO_SECRET_KEY in a .env file outside your public folder, or open a request at https://barbrick.ca/submitticket.php and we'll set them for you, usually the same day. See Set environment variables for apps. Read them with os.environ["NAME"].
Database
MySQL: pip install mysqlclient or pymysql. See Create a MySQL database and user. PostgreSQL isn't offered; see Use PostgreSQL.
Restart
Click Restart in Developer after changes, or:
touch ~/apps/bakery/tmp/restart.txt
If something goes wrong
| Problem | Fix |
|---|---|
| "Incomplete response received from application" | Read the log. Often an import error |
ModuleNotFoundError |
Install requirements in the app's virtualenv, not system Python |
| Static files missing | Run collectstatic, and confirm STATIC_ROOT is web-accessible |
DisallowedHost |
Add the domain to ALLOWED_HOSTS |
| Slow first request | The app starts on demand after idle |
Still stuck? Ask us and we'll walk you through it.
