🌟 We are Open Source! Check out our repository on GitHub

Django Project Structure

A scalable and maintainable folder structure for Django applications

File Structure

  • myproject
    • __init__.py
    • settings.py
    • urls.py
    • wsgi.py
    • asgi.py
    • apps
      • __init__.py
      • home
        • __init__.py
        • models.py
        • views.py
        • urls.py
        • templates
        • tests.py
      • about
        • __init__.py
        • models.py
        • views.py
        • urls.py
        • templates
        • tests.py
    • static
      • css
      • js
      • images
    • templates
      • base.html
      • home.html
      • about.html
    • media
      • uploads
    • tests
      • __init__.py
      • test_models.py
      • test_views.py
  • manage.py
  • requirements.txt
  • .gitignore
  • README.md

Directory Structure Explanation

myproject/

The main project folder containing all Django related files and folders.

myproject/__init__.py

An empty file that tells Python that this directory should be considered a Python package.

myproject/settings.py

Contains settings and configurations for the Django project.

myproject/urls.py

Contains URL declarations for the Django project; a “table of contents” of your Django-powered site.

myproject/wsgi.py

An entry-point for WSGI-compatible web servers to serve your project.

myproject/asgi.py

An entry-point for ASGI-compatible web servers to serve your project.

myproject/apps/

Contains individual apps of the Django project, each with its own folder and multiple files.

myproject/apps/home/

Folder for the home app, containing its models, views, templates, and tests.

myproject/apps/home/models.py

Defines the data models for the home app.

myproject/apps/home/views.py

Contains the view logic for the home app.

myproject/apps/home/urls.py

Defines the URL routes for the home app.

myproject/apps/home/templates/

Contains HTML templates for the home app.

myproject/apps/home/tests.py

Contains unit tests for the home app.

myproject/apps/about/

Folder for the about app, containing its models, views, templates, and tests.

myproject/apps/about/models.py

Defines the data models for the about app.

myproject/apps/about/views.py

Contains the view logic for the about app.

myproject/apps/about/urls.py

Defines the URL routes for the about app.

myproject/apps/about/templates/

Contains HTML templates for the about app.

myproject/apps/about/tests.py

Contains unit tests for the about app.

myproject/static/

Stores static files like CSS, JavaScript, and images used in the project.

myproject/static/css/

Contains CSS files for styling the project.

myproject/static/js/

Contains JavaScript files for client-side functionality.

myproject/static/images/

Contains image files used in the project.

myproject/templates/

Contains base HTML templates and other shared templates for the project.

myproject/templates/base.html

Base HTML template that other templates extend from.

myproject/templates/home.html

HTML template for the home page.

myproject/templates/about.html

HTML template for the about page.

myproject/media/

Stores media files uploaded by users, such as images and documents.

myproject/media/uploads/

Contains uploaded files by users.

myproject/tests/

Contains unit and integration tests for the project.

myproject/tests/__init__.py

An empty file that tells Python that this directory should be considered a Python package.

myproject/tests/test_models.py

Contains unit tests for the project's models.

myproject/tests/test_views.py

Contains unit tests for the project's views.

manage.py

A command-line utility that lets you interact with this Django project in various ways.

requirements.txt

Lists the Python dependencies required for the Django project.

.gitignore

Specifies files and directories that should be ignored by Git version control.

README.md

Documentation file providing an overview and instructions for the project.