Django Folder Structure

Django Folder Structure

Table of contents

No heading

No headings in the article.

The Django folder structure is a standard way to organize files and directories within a Django project. At the root level, there are typically files like manage.py and settings.py, which define project settings and configurations. A basic folder structure for a Django project can help you organize your files and make your project more scalable and maintainable. Here is a sample folder structure:

project_name/
├── config/
│   ├── settings/
│   │   ├── base.py
│   │   ├── local.py
│   │   ├── development.py
│   │   ├── staging.py
│   │   ├── production.py
│   ├── urls.py
│   ├── wsgi.py
│   ├── asgi.py
│
├── apps/
│   ├── app1/
│   │   ├── migrations/
│   │   ├── templates/
│   │   ├── static/
│   │   ├── tasks/
│   │   ├── utils/
│   │   ├── management/
│   │   ├── api/
│   │   │   ├── v1/
│   │   │   │   ├── serializers.py
│   │   │   │   ├── views.py
│   │   │   │   ├── filters.py
│   │   │   ├── v2/
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── choices.py
│   │   ├── models.py
│   │   ├── signals.py
│   │   ├── urls.py
│   │   ├── views.py
│   ├── app2/
│   ├── app3/│
│
├── static/
│   ├── css/
│   ├── js/
│   ├── img/
│
├── media/
│
├── templates/
│
├── utils/
│
├── tasks/
│
├── management/
│
├── manage.py
│

In this structure, the main project folder contains three main directories: config, apps, static, and media.

  • config directory contains all the settings and configurations of the Django project. It includes settings for different environments such as base.py (base settings), local.py (local development settings), development.py (development environment settings), staging.py (staging environment settings), and production.py (production environment settings). It also includes urls.py (main project URL configuration), wsgi.py (Web Server Gateway Interface configuration), and asgi.py (Asynchronous Server Gateway Interface configuration).

  • apps directory contains all the apps that are part of the Django project. Each app has its own directory containing models, views, templates, static files, and tests. This structure helps to keep the code organized and makes it easier to manage.

    • tasks/: This directory contains files for background tasks such as Celery tasks.

    • templates/: This directory contains all of the app's templates.

    • static/: This directory contains all of the app's static files, such as CSS, JavaScript, and images.

    • utils/: This directory contains utility files that are used across multiple apps in the project, such as common helper functions, mixins, or abstract classes.

    • management/: This directory contains custom management commands for the Django project. These commands can be used to automate tasks, create database entries, and perform other administrative functions.

    • api/: This directory is inside each app and contains versioned subdirectories for the API views. Each versioned subdirectory has its own serializers.py, filters.py and views.py files.

      • v1/ and v2/: These directories are inside each app's api/ directory and represent version 1 and version 2 of the API. Each versioned subdirectory can have its own serializers.py, filters.py and views.py files. which allows for different versions of the API to have different serializers and filters.
  • static directory contains all the static files used in the project such as CSS, JavaScript, and images.

  • media directory contains all the media files uploaded by the users of the website.

  • templates directory contains all the HTML templates used in the project.

  • manage.py is the entry point to the Django project and is used to execute various Django commands such as starting the development server, running database migrations, etc.

This is just a basic structure, and depending on the size and complexity of your project, you may need to modify it.