Use the Python web app profile with Gunicorn
Choose the Python web app profile, include Gunicorn in requirements.txt, and set a start command that binds to 0.0.0.0 on $SERVER_PORT. Bothosting gives the deployment an HTTPS address. A small Flask app fits the free Spark plan. Django with an admin site and a database is more comfortable on a paid plan with 1 GB or more.
Flask
flask>=3.0
gunicorn>=22python -m pip install -r requirements.txt && gunicorn app:app --bind 0.0.0.0:"$SERVER_PORT" --workers 2Here app:app means the object app in app.py. Change it to match your module.
Django
python -m pip install -r requirements.txt && python manage.py migrate --noinput && gunicorn mysite.wsgi --bind 0.0.0.0:"$SERVER_PORT" --workers 2Add the deployment’s hostname to ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS. Read SECRET_KEY and the database URL from Variables, and set DEBUG to false. Serve static files with WhiteNoise or run collectstatic before starting.
Test the first request
Start the deployment and watch Console for Gunicorn’s Listening at line. Open the HTTPS address from Settings and request a page you know exists. If the page does not load, check the bind address and port first. See an app that starts but is unreachable. ASGI frameworks follow the same steps with Uvicorn. See hosting FastAPI.