This project allows you to quickly begin a Django project on Clever Cloud.
A working version of Python. This project has been tested on Python 3.11+ with Django 5.0.4.
By default, Django will use a local sqlite database that won't persist between deployments. So you need to choose a non-local technology.
Django supports some DBs and Clever Cloud can host somes as add-ons.
To keep it simple, you can run it either on MySQL or PostgreSQL. Add the suitable dependancy to requirements.txt
according to your DB.
For local work, you can grab PostgreSQL easily; or MySQL and its compatible alternative MariaDB.
First you need to fork the project or duplicate it.
If you want to use a database such as PostgreSQL, refer to the offical Django documention.
This tutorial will use the Clever Tools CLI.
It will allow you to create, configure and deploy your application on Clever Cloud from console.
In the following steps, we will suppose that you name (adapt to your needs) in the Clever Cloud dashboard :
- your application :
django-cc
- your corresponding database add-on if needed :
django-cc-pg
(for example)
At the root of the project :
clever login
Log in the UI and close it. Then create your Python application and PostgreSQL add-on :
clever create --type python --region par django-cc
clever addon create --region eu --plan dev --link django-cc postgresql-addon django-cc-pg
More information on parameters HERE.
If needed, you can set the scaling :
clever scale --min-flavor pico --max-flavor pico
clever scale --min-instances 1 --max-instances 1
More information on scaling HERE.
You need to setup some Environment variables accordingly to your settings.py
:
clever env set CC_PYTHON_VERSION "3"
clever env set CC_PYTHON_MODULE "ccdjangodemo.wsgi:application"
clever env set STATIC_FILES_PATH "static/"
clever env set STATIC_URL_PREFIX "/static"
More information on Python environement variables HERE.
Once deployed, from the Console, your environement variables will look like that on Expert mode:
CC_PYTHON_VERSION="3"
CC_PYTHON_MODULE="ccdjangodemo.wsgi:application"
STATIC_FILES_PATH="static/"
STATIC_URL_PREFIX="/static"
Nothing else left to do, just go on and deploy your app :
clever deploy
Note :
If deployement failed with some error like :
django.db.utils.OperationalError: could not translate host name "XXXXXXXXXX-postgresql.services.clever-cloud.com" to address: Name or service not known
It only means that you deployed too quickly after creating the PG add-on and name propagation has not yet been done. Wait a bit and try again later.
Your application automatically has a domain pointing to it. You can obtain it though :
clever domain
To add other domains, more information HERE.