> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shardcloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Host Django Applications

> Learn how to create and deploy Django applications on Shard Cloud.

## Introduction

This guide covers deploying Django applications on Shard Cloud. Django is a high-level Python web framework for rapid development.

## Creating Your Project

Ensure you have **Python** and **pip** installed.

### Installing Django

```bash theme={null}
pip install django gunicorn
```

### Creating a New Project

```bash theme={null}
django-admin startproject myproject
cd myproject
```

### Basic Django Application

Create a simple view in `myproject/views.py`:

```python myproject/views.py theme={null}
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello from Django!")
```

Update `myproject/urls.py`:

```python myproject/urls.py theme={null}
from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, name='index'),
]
```

### Settings Configuration

Update `myproject/settings.py`:

```python theme={null}
ALLOWED_HOSTS = ['*']
DEBUG = False
```

### Requirements File

Create a `requirements.txt`:

```txt requirements.txt theme={null}
django
gunicorn
```

## Production Server with Gunicorn

<Warning>
  Django's built-in server is not suitable for production. Always use Gunicorn.
</Warning>

## Shard Cloud Configuration

Create a `.shardcloud` file:

```systemd .shardcloud theme={null}
DISPLAY_NAME=Django App
DESCRIPTION=Python Django Application
LANGUAGE=python
MEMORY=512
VERSION=recommended
SUBDOMAIN=my-django-app
CUSTOM_COMMAND=gunicorn --bind 0.0.0.0:80 --workers 2 myproject.wsgi:application
```

<Note>Run migrations locally before deploying: `python manage.py migrate`</Note>

## Deploying

<Steps>
  <Step title="Run Migrations Locally">
    ```bash python manage.py migrate python manage.py collectstatic --noinput theme={null}
    ```
  </Step>

  <Step title="Prepare Your Files">
    Ensure you have: - Your Django project folder - `requirements.txt` -
    `.shardcloud` - `db.sqlite3` (if using SQLite)
  </Step>

  <Step title="Exclude Unnecessary Files">
    Remove: `__pycache__/`, `venv/`, `*.pyc`
  </Step>

  <Step title="Create ZIP Archive">Compress your project folder.</Step>

  <Step title="Upload to Shard Cloud">
    Go to [Shard Cloud Dashboard](https://shardcloud.app/dash/applications) and
    upload.
  </Step>
</Steps>

## Additional Resources

Visit the [official Django documentation](https://docs.djangoproject.com/) for more information.

## Troubleshooting

<AccordionGroup>
  <Accordion title="DisallowedHost error">
    Add your domain to `ALLOWED_HOSTS` in `settings.py` or use `['*']`.
  </Accordion>

  <Accordion title="Static files not loading">
    Run `python manage.py collectstatic` before deploying.
  </Accordion>
</AccordionGroup>
