Django ๐Ÿ

Django 4.1.7 Python 3.11 made-with-bash Ubuntu 22.10 Become a sponsor to JV-conseil Follow JVconseil on Twitter Follow JVconseil on Mastodon Follow JV conseil on GitHub

First launch a PostgreSQL Server job to be able to connect it later on to this Django job.

Parameters

DjangoJobParameters

Note

postgres.database.ucloud.sdu.dk ๐Ÿ‘€ is the hostname string to connect to the running PostgreSQL Server job.

๐Ÿ‘‰ See also DjangoJobParameters.json template.

Usage

  1. Once the Django job has started and all the initialisation has been completed, click on the Open terminal blue button in the top right corner.

  2. In Terminal navigate to the ucloud folder cd /work/ucloud

  3. Then launch the script with . main.sh

  4. Then follow instructions starting after Do you want to manage Django question.

Environment variables

Available environment variables created in UCloud job to interact within Django app.

import os

...

UCLD_ALLOWED_HOSTS = os.environ.get("UCLD_ALLOWED_HOSTS", "")
UCLD_HOSTNAME = os.environ.get("UCLD_HOSTNAME", "")
UCLD_PATH_TO_DATA = os.environ.get("UCLD_PATH_TO_DATA", "")

Allowing integration with Django settings.py

ALLOWED_HOSTS = ["127.0.0.1", "localhost"]

if UCLD_HOSTNAME:
    ALLOWED_HOSTS += [UCLD_HOSTNAME]

if UCLD_ALLOWED_HOSTS:
    ALLOWED_HOSTS += UCLD_ALLOWED_HOSTS.split(" ")

CSRF_TRUSTED_ORIGINS = [f"https://{_host}" for _host in ALLOWED_HOSTS]

UCLD_PATH_TO_DATA = os.environ.get(
    "UCLD_PATH_TO_DATA", os.path.join(BASE_DIR, "dumpdata")
)

Reading ๐Ÿ“š

  • UCloud Apps Django documentation.

Sponsorship

If this project helps you, you can offer me a cup of coffee โ˜•๏ธ :-)

Become a sponsor to JV-conseil