Project Structure
Our Django applications follow a particular project structure. It's worked well for us, and hopefully it does for you too!
We aim to make consistent use of our project structure for all Django products, as far as possible. Modifications are made on a project-by-project basis, however we try to keep the core Django structure the same.
Example Project Structure
An example project structure, highlighting the more important files and folders is shown below:
apps/
blog/ - application folder for a standalone blog
page/ - application folder for common web pages
core/ - application folder for the core site
utils/ - folder to store utilities and helpers for custom applications
config/
settings/
common.py - base site settings
dev.py - additional development site settings
prod.py - additional production site settings
urls.py - site url patterns
docker/
django/
Dockerfile - docker configuration for development
Dockerfile.prod - docker configuration for production
nginx/ - nginx configuration for deployment
media/ - application media folder
static/ - application static content
dev.env - environment variables for development
docker-compose.dev.yml - docker-compose for development
docker-compose.prod.ssl.yml - docker-compose for production (with ssl)
docker-compose.prod.yml - docker-compose for production
manage.py - Django cli caller
prod.env - environment variables for production
README.md - readme file for product
requirements.txt - requirements for development and production
Here, we are leveraging Docker and docker-compose in order to build and run the application. Each docker configuration has an associated compose .yml file (e.g. docker-compose.dev.yml), a docker configuration file (e.g. Dockerfile), and it will make use of our requirements file to know which packages and versions to use as part of the build (requirements.txt) as well as an appropriate environment variable file for that environment (e.g. dev.env).
It is also worth noting that the environment variable file used by Docker will specify which Django settings configuration to use. For example, config.setting.dev is used for development, while config.settings.prod is used for production. However, both configurations leverage common.py as a base.
We also have separate folders for our application media versus static content. We typically serve static content via NGINX, but many of our products include environment variable options to allow use of an external S3 store to serve media files.
In the apps folder, we tend to include three base apps for all products. These include:
core - an app including all models and views associated with site configuration settings and global options.
page - an app covering common and more static nature web pages (e.g. landing page, about us, contact us etc.).
utils - not an application, but rather a collection of mixins which we have put together for users of our products to make use of.
Finally, we include a README.md file for all of our products. That file includes instructions on how to build the application via docker-compose as well as a list of helpful commands.
Last updated