Django Project Structure

Django Project Structure

December 16, 2023

I love the Python Programming Language, and its most popular Web Framework - Django. In fact I love it so much that it is reflected in my pseudonym. I am no expert django dev, however I understand the design. this blog post unravels the intricacies of Django’s structural design.

Design

Django follows a Model-View-Template (MVT) architectural design pattern.

  • Model: Defines the data structure of the application. Models are used to interact with the database.

  • View: Handles user requests, processes data from the model, and renders templates.

  • Template: Handles how data is displayed. Typically written in HTML with Django template language.

Project & App

  • Project: A Django project is the entire web application.
  • App: A module within a project that performs a specific function.

Typical Project Structure

    • manage.py
      • _init_.py
      • settings.py
      • urls.py
      • wsgi.py
  • manage.py: A command-line utility for interacting with the project, such as running development servers, creating database tables, creating superusers, making migrations, etc.

    myproject/: Named after the core project. contains global urls, settings.

    __init__.py - empty file that indicates that this directory should be treated as a Python Package.

    settings.py: global configuration settings for the project, including database connections, static files, middleware, and more.

    urls.py: Defines the URL patterns for the project.

    wsgi.py: configuration for the WSGI server, which is responsible for serving the web application.

    asgi.py: similar to WSGI, but it performs some additional functions

    App Structure

    • manage.py
      • init.py
      • admin.py
      • apps.py
      • models.py
      • tests.py
      • views.py
  • migrations/: propagating changes you make to your models

    admin.py: file used to display the admin panel, connect models to the panel and make changes to admin interface.

    apps.py: configures the Django app.

    models.py: To create models so that we can query data.

    tests.py: contains code for application testing.

    views.py: Python functions that takes http requests and returns http response.

    Static

    – stores images, CSS, or JS files.

    Templates

    – a HTML document or a Python string mark-up using the Django template language.