Deploy Django on Hostim.dev
This guide shows how to deploy a Django app on Hostim.dev from a Git repository.
Quick start: Use the "Django Demo" template to skip the setup.
π Open the Console Click "+ New Project", pick Django Demo, and you're good to go.
Want to customize or start fresh? This guide walks you through the manual setup.
0. Create a Projectβ
Start by creating a new project:
- Open your Hostim.dev dashboard
- Click Create Project
- Pick one:
- Scratch β start fresh
- Template β use Django Demo for a prebuilt setup
- Docker Compose β paste your own setup
- Choose Scratch for this guide
- Name it something like
django-demo
and hit Create Project
1. Use the Example Django Appβ
We're using this example Django app:
π https://github.com/hostimdev/demo-django
No need to clone it unless you're running locally. If so, follow its README for local setup.
π³ The repo already has a working
Dockerfile
anddocker-compose.yml
2. Deploy on Hostim.devβ
β οΈ Set things up in this order: Volume β Database β Redis β App. This makes sure all pieces are connected when the app starts.
2.1. Create a Volume for Mediaβ
- In your dashboard, click Create Service β New Volume
- Name it
media-data
(or anything you like) - Pick a plan
- Click Create Volume
2.2. Add a MySQL Databaseβ
- Click Create Service β New MySQL
- Name it
db
- Pick a plan
- Click Create MySQL
2.3. Add a Redis Instanceβ
- Click Create Service β New Redis
- Name it
redis
- Pick a plan
- Click Create Redis
2.4. Create the Django Appβ
- Click Create Service β New App
- Choose Git for deployment type
- Enter:
https://github.com/hostimdev/demo-django
- Set the branch to
main
- Leave Dockerfile path as
Dockerfile
- Choose your plan and replicas
- Under Volume Mounts, click Attach Volume
- Pick
media-data
- Mount path:
/app/media
- Pick
- Enable HTTP Service
- Set HTTP Port to
8000
- Make the app public (or not)
- Click Create App
2.5. Set Up Environment Variablesβ
- Go to your app > Envs tab
- Add these variables:
DEBUG=1
SECRET_KEY=automatically_generated_32_char_key
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
REDIS_HOST=$(REDIS_REDIS_HOST)
REDIS_PORT=$(REDIS_REDIS_PORT)
MYSQL_DATABASE=$(DB_MYSQL_DATABASE)
MYSQL_USER=$(DB_MYSQL_USER)
MYSQL_PASSWORD=$(DB_MYSQL_PASSWORD)
MYSQL_HOST=$(DB_MYSQL_HOST)
MYSQL_PORT=$(DB_MYSQL_PORT)
Variable | What it does |
---|---|
DEBUG | Enables debug mode for dev |
SECRET_KEY | Automatically generated |
DJANGO_ALLOWED_HOSTS | Whitelisted hosts |
MYSQL_* | Filled from the MySQL service |
REDIS_* | Comes from the Redis service |
Click Save Changes when you're done.