This is a Django starter project that you can use as the starting point to develop your own and deploy it on Cloud Platform like Heroku.
- Red Hat UBI 8 with Python 3.9 Docker base image
- Visual Studio Code Docker integration
- Development and Production Docker containers
- Django 3.2 LTS
- Production Web Servers with NGINX and Gunicorn
- HTTPS local development with django-extensions
- Decoupled production, staging, test, and local settings with python-decouple
- Live reload server for local development with django-livereload-server
- Local debugging with django-debug-toolbar
Apart from the regular files created by Django (webapp/*
, manage.py
), this repository contains:
.certs/ - OpenSSL certificates folder for HTTPS support
.devcontainer/ - Vistual Studio Code development configuration folder
├── devcontainer.json - Development container configuration file
└── docker-compose.yml - Docker compose file
└── Dockerfile - Docker configuration file for development
├── requirements.dev.txt - List of development dependencies
.html-template/ - Folder to store an HTMl template for development purposes
.vscode/ - Visual Studio Code configuration files
.static/ - Static files folder: css, js, and images
.env - Environment variables file
.gitattributes
.gitignore
Dockerfile - Docker configuration file for production
nginx.conf - NGINX configuration file for production
requirements.txt - List of production dependencies
start-server.sh - Shell file that executes production services
Please be sure to read the following warnings and considerations before running this code on your local workstation, shared systems, or production environments.
The sample application code and templates in this repository contain database connection settings and credentials that rely on being able to use SQlite.
This is a minimal Django 3.2 project. To run this project in your development machine, follow these steps:
- Clone the starter template
$ git clone https://github.com/alenaifuino/django-template.git <webapp_name>
- Run Visual Studio Code inside the directory where you cloned the repo
$ cd <webapp_name>
$ code .
- Press
CTRL
+Shift
+P
and selectRemote Containers: Open Folder in Container...
- Open your browser and go to https://127.0.0.1:8000, you will be greeted with a welcome page.
From this initial state you can:
- Create new Django apps
- Rename the Django project
- Update settings to suit your needs
- Install more Python libraries and add them to the
requirements.txt
or.devcontainer/requirements.dev.txt
files
You should change the value in the .env file. For security purposes, make sure to set this to a random string as documented here.
You should set the value in the .env file. Default value is "localhost, 127.0.0.1".
You should set the value in the .env file. Default value is "127.0.0.1".
You should define their values as environment variables in the production environment. They will be used by the start-server.sh
script to create the superuser for the admin interface.
The server_name
value should be updated with the public domain name for your web server.
You can deploy this application without a configured database in your Cloud Platform project, in which case Django will use a temporary SQLite database that will live inside your application's container, and persist only until you redeploy your application.
After each deploy you get a fresh, empty, SQLite database. That is fine for a first contact with Django, but sooner or later you will want to persist your data across deployments.
To do that, you should add a properly configured database server or ask your Cloud Platform administrator to add one for you. Then update the settings file for staging and production to update the DATABASES
variable to match your database settings. Database user and password should probably be defined as environment variables in your production container.
Redeploy your application to have your changes applied, and open the welcome page again to make sure your application is successfully connected to the database server.
If you get stuck at some point, or think that this document needs further details or clarification, you can give feedback and look for help by filing an issue.