Skip to main content

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

pip install django gunicorn

Creating a New Project

django-admin startproject myproject
cd myproject

Basic Django Application

Create a simple view in myproject/views.py:
myproject/views.py
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello from Django!")
Update myproject/urls.py:
myproject/urls.py
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:
ALLOWED_HOSTS = ['*']
DEBUG = False

Requirements File

Create a requirements.txt:
requirements.txt
django
gunicorn

Production Server with Gunicorn

Django’s built-in server is not suitable for production. Always use Gunicorn.

Shard Cloud Configuration

Create a .shardcloud file:
.shardcloud
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
Run migrations locally before deploying: python manage.py migrate

Deploying

1

Run Migrations Locally

python manage.py migrate python manage.py collectstatic --noinput
2

Prepare Your Files

Ensure you have: - Your Django project folder - requirements.txt - .shardcloud - db.sqlite3 (if using SQLite)
3

Exclude Unnecessary Files

Remove: __pycache__/, venv/, *.pyc
4

Create ZIP Archive

Compress your project folder.
5

Upload to Shard Cloud

Go to Shard Cloud Dashboard and upload.

Additional Resources

Visit the official Django documentation for more information.

Troubleshooting

Add your domain to ALLOWED_HOSTS in settings.py or use ['*'].
Run python manage.py collectstatic before deploying.