# Deploy a Django or FastAPI app

Put a Python web app online from your repository: Python installed for you, a fresh environment per version, migrations applied, the app kept running.

This guide puts a Django or FastAPI app online from your Git repository. Python is installed on the server with the first Python site if it is missing.

## What you need

- A **Website server** that is **Online**.
- Your project at GitHub, GitLab or Bitbucket, connected under **Code hosting**, with a `requirements.txt` or `pyproject.toml`.
- A database for your data (PostgreSQL or MySQL/MariaDB). A SQLite file inside your code would be replaced by each new version.

## Steps

1. **Add the site.** Choose **Add a site**, then **Django** or **FastAPI** in the list under **Or pick the exact kind of site**.

2. **Address.** Choose the server and type the address.

3. **Code and settings.** Pick the repository and **Branch**. Tick **Create a database for this site** if you want Fuzops to create one on this server. Choose **Add site** on the **Review**.

4. **Add your settings.** Until you publish, your address shows a short "waiting for its first version" page instead of an error. Open **Updates** › **Environment**: add your secret key, allowed hosts, database address and anything else your app reads. Choose **Save and publish update**.

5. **Watch the first update.** Each update gets the code, installs your Python packages in a fresh environment for that version, and then:
   - for **Django**: collects static files, applies database migrations and starts the app. Static and media files are served directly by the web server;
   - for **FastAPI**: starts the app found in your code (for example `app = FastAPI()` in `main.py`).

   The new version starts beside the running one; visitors move over only when it answers.

6. **Add background work if you need it.** For a task queue (Celery, for example), add a background process for the site under the server's **Background processes**. See [Background processes](https://internal.fuzops.com/docs/background-processes-and-scheduled-jobs).

7. **Point your domain and turn on HTTPS.** See [Point your domain and turn on HTTPS](https://internal.fuzops.com/docs/guides/point-your-domain-and-turn-on-https).

## What you should see

The site page says it is live, and the **Updates** tab shows the update as **Published**.

![The update steps of a site, each with its result](https://internal.fuzops.com/docs-img/site-update-steps.webp "Update steps work the same way for every kind of site.")

## If it goes wrong

- **Stopped while installing packages**: a package needs a system library or a newer Python. **See what went wrong** shows the error from pip.
- **Stopped at "Restart the app"**: the app did not start. Read the lines for the Python error (often a missing setting in the Environment, or `ALLOWED_HOSTS` in Django), fix it and **Publish again**.
- **Static files are missing (Django)**: open the update page and check that collecting the static files succeeded; the error is shown there.
