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/

      • - base site settings

      • - additional development site settings

      • - additional production site settings

    • - site url patterns

  • docker/

    • django/

      • Dockerfile - docker configuration for development

      • - 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 for development

  • - docker-compose for production (with ssl)

  • - docker-compose for production

  • - Django cli caller

  • prod.env - environment variables for production

  • - 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., 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, is used for development, while is used for production. However, both configurations leverage 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:

  1. core - an app including all models and views associated with site configuration settings and global options.

  2. page - an app covering common and more static nature web pages (e.g. landing page, about us, contact us etc.).

  3. 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 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