what is django - projectsteward-io/steward-learning GitHub Wiki

Introduction to Django

Django is a high-level, open-source web framework written in Python that enables developers to build web applications quickly and efficiently. It follows the Model-View-Template (MVT) architectural pattern and is designed to help developers create secure, scalable, and maintainable web applications.

Django’s tagline is:

"The web framework for perfectionists with deadlines."

This highlights its ability to handle common web development tasks, allowing developers to focus on building features rather than reinventing the wheel.


How Does Django Work?

Django provides a structured approach to building web applications. Here’s an overview of its core architecture and workflow.

1. Model-View-Template (MVT) Architecture

Django follows the MVT pattern, which separates concerns in a web application:

  • Model: Defines the data structure and interacts with the database using Django’s ORM (Object-Relational Mapping). It translates database tables into Python classes.
  • View: Handles business logic, processes user requests, and communicates with models. It returns responses based on user input.
  • Template: Controls how the data is presented to the user. It uses Django’s templating engine to render dynamic HTML pages.

2. How Django Handles a Web Request

When a user visits a Django-powered website, the request follows these steps:

  1. User Requests a Page

    • The user enters a URL (e.g., www.example.com/home).
    • Django’s URL dispatcher (urls.py) matches the request to a view function.
  2. View Processes the Request

    • The corresponding view function (views.py) executes the required logic.
    • It may interact with models (database) to retrieve or store data.
  3. Templates Render the Response

    • If needed, the view passes data to an HTML template.
    • Django’s template engine dynamically renders the page with dynamic content.
  4. Response is Sent to the Browser

    • The rendered HTML page is returned to the user’s browser.

3. Key Features of Django

ORM (Object-Relational Mapping) – Interact with the database using Python instead of SQL.
Authentication System – Built-in support for user authentication, login, and permissions.
Admin Panel – A pre-built, customizable admin interface for managing application data.
Security Features – Django protects against SQL injection, XSS (cross-site scripting), and CSRF (cross-site request forgery).
Scalability – Can handle large amounts of traffic efficiently.
Third-Party Packages – A rich ecosystem of reusable apps and plugins via Django Packages.