Python Project
Python projects are used to deploy Django, Flask, FastAPI, and other Python web applications.
Prerequisites
- Install Python runtime: Apps > Runtimes > Python
- Project source code
Deployment Steps
- Upload project code to the server
- Create virtual environment and install dependencies:
bash
cd /opt/ace/project/myapp
python3.13 -m venv venv
source venv/bin/activate
pip install -r requirements.txt- Create project:
- Project Name:
myapp - Project Directory:
/opt/ace/project/myapp - Startup Command: See examples below
- Project Name:
- Enable Reverse Proxy
Startup Command Examples
Django
bash
# Development server (not recommended for production)
/opt/ace/project/myapp/venv/bin/python manage.py runserver 0.0.0.0:8000
# Using Gunicorn (recommended)
/opt/ace/project/myapp/venv/bin/gunicorn myproject.wsgi:application -b 0.0.0.0:8000 -w 4
# Using uWSGI
/opt/ace/project/myapp/venv/bin/uwsgi --http 0.0.0.0:8000 --module myproject.wsgiFlask
bash
# Development server (not recommended for production)
/opt/ace/project/myapp/venv/bin/python app.py
# Using Gunicorn (recommended)
/opt/ace/project/myapp/venv/bin/gunicorn app:app -b 0.0.0.0:8000 -w 4FastAPI
bash
# Using Uvicorn
/opt/ace/project/myapp/venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000
# Using Gunicorn + Uvicorn Workers (recommended)
/opt/ace/project/myapp/venv/bin/gunicorn main:app -b 0.0.0.0:8000 -w 4 -k uvicorn.workers.UvicornWorkerCommon Framework Configurations
Django Production Configuration
settings.py:
python
DEBUG = False
ALLOWED_HOSTS = ['your-domain.com']
STATIC_ROOT = '/opt/ace/project/myapp/static/'Collect static files:
bash
/opt/ace/project/myapp/venv/bin/python manage.py collectstaticFastAPI Example
python
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}Gunicorn Configuration
Create gunicorn.conf.py:
python
bind = "0.0.0.0:8000"
workers = 4
worker_class = "sync" # Or "uvicorn.workers.UvicornWorker" for FastAPI
timeout = 30
keepalive = 2Startup command:
bash
/opt/ace/project/myapp/venv/bin/gunicorn -c gunicorn.conf.py myproject.wsgi:applicationVirtual Environment
It is strongly recommended to use virtual environments to isolate project dependencies:
bash
# Create virtual environment
python3.13 -m venv venv
# Activate virtual environment
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Deactivate virtual environment
deactivateCommon Issues
Dependency Installation Failed
Some packages require compilation, ensure necessary system dependencies are installed:
bash
# AlmaLinux/Rocky Linux
yum install gcc python3-devel
# Ubuntu/Debian
apt install gcc python3-devStatic Files 404
Django production environment needs to configure Nginx to serve static files directly, or use WhiteNoise.
Database Connection Issues
Check database configuration and network connection, ensure the database service is running properly.
