> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.squarecloud.app/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to host Django on Square Cloud (step by step)

Looking for **where to host a Django app** or the **best way to put a Django app online**? This guide shows the step-by-step to host Django on Square Cloud — from `settings.py` (ALLOWED_HOSTS) to deploying with Gunicorn, running 24/7.

## 1. Prerequisites
* **Square Cloud Account:** Create your account via the [Registration Page](https://squarecloud.app/pt-br/signup) (Email or GitHub).
* **Active Plan:** A paid plan is required for hosting. Check the [pricing here](https://squarecloud.app/pt-br/pricing).

---

## 2. Production Settings (settings.py)

Before deploying, you need to adjust your Django project's `settings.py` file to allow Square Cloud traffic:

* **ALLOWED_HOSTS:** Add the subdomain you intend to use and the Square Cloud domain.
```python
ALLOWED_HOSTS = ['yoursubdomain.squareweb.app', 'yourdomain.com', 'localhost', '127.0.0.1']
```
* **DEBUG:** For production, remember to set `DEBUG = False`.
* **Static Files:** Make sure to configure `STATIC_ROOT` so Django knows where to collect static files.

---

## 3. Performing the Deployment

1. **Cleanup:** Remove unnecessary folders such as `venv/`, `.git/`, and `__pycache__` cache files.
2. **Compression:** Create a `.zip` file containing the root of the project (where the `manage.py` file is located). The `requirements.txt` file must be in the project root and contain at least:
```text
Django
gunicorn
```
3. **Upload:** In the Square Cloud Dashboard, click on upload new application.
4. **Web Publishing:** In the submission menu, check the **"Publish to Web"** option.
5. **Subdomain:** Define the desired subdomain (e.g., `myproject.squareweb.app`).
6. **Custom Start Command:** For your Django application to run in production, you must configure the start command to use Gunicorn on port **80**. At the time of upload or in the `squarecloud.app` file, use:
```bash
python -m gunicorn --bind 0.0.0.0:80 your_project.wsgi:application
```
* **`--bind 0.0.0.0:80`**: Binds the application to the interface and port required by Square Cloud.
* **`your_project.wsgi:application`**: Replace `your_project` with the name of the folder containing the `wsgi.py` file.

---

## 4. Custom Domains (Standard+ Plan)

If you have a **Standard plan or higher**, you can use your own domain:
* Configure the domain (e.g., `www.yoursite.com`) in the **Network** tab.
* **SSL (HTTPS)** is automatically configured and renewed by Square Cloud at no additional cost.

---

## 5. Optimization and Security Tips

* **Static Files:** In Django, remember to run the "python manage.py collectstatic" command or configure Gunicorn/Middleware (such as WhiteNoise) to serve static files in production.
* **Environment Variables:** Use the Dashboard's **ENV** tab to hide your `SECRET_KEY` and database credentials. Never leave passwords exposed in the code sent to the repository or dashboard.
* **Database:** For production, use **PostgreSQL** or **MySQL** instances available on Square Cloud, avoiding the use of SQLite in applications that require scalability.