Origin
Created by Lawrence Journal-World newspaper in 2003.
- they created multiple websites which led to repeated code and design patterns.
Open sourced in 2005.
Well written documentation is key part of Django.
Philosophy of Django
Purpose: Modularity and Reusability.
MVC
Model-View-Controller pattern is renamed to Model-View-Template in Django.
- Pattern segregates data (models), user interfaces (views), and control logic (templates) into distinct layers.
Structure and Hierarchy
Collection of settings, configurations, and apps coordinate to form a complete entity.
- App is a smaller, self-contained module within the project that serves a specific purpose.
App can be a blog, auth system, or other standalone functionality.
Different apps contain their own MVC.
project_name/
├── manage.py
├── project_name/
│ ├── __init__.py
│ ├── asgi.py
│ ├─ settings.py
│ ├─ urls.py
│ ├── wsgi.py
├── app1/
├── app2/
...
├── static/
├── media/
├── templates/
Template Files
manage.py
- gateway to various Django management commands.
- tool to initiate the development server, create applications, run migrations, and more.
project_name/settings.py
- From database configurations to middleware lists, this is where you define how your application functions.
project_name/urls.py
- The URL dispatcher maps URLs to views.
- This file determines which view is displayed when a specific URL is accessed.
project_name/wsgi.py
- Web Server Gateway Interface.
- entry point for your application when deployed on a production server.
- bridge connecting your application to the web server, enabling it to handle incoming requests.
project_name/asgi.py
- Asynchronous Server Gateway Interface.
- entry point for asynchronous web servers.
- facilitates the handling of asynchronous HTTP requests.
project_name/__init__.py
- transforms a directory into a Python package
- organizing and importing modules across your project
Generated Files
models.py
- Django's ORM data structure.
- Each model class represents a table in the database.
views.py
- logic that defines how your application interacts with users' requests.
- View handles data processing, rendering templates, and responding to actions.
- Transforms user interactions to tangible responses.
tests.py
- You write unit tests here.
admin.py
- how your appliaction's models are presented in Django's admin interface.
migrations
- directory with all changes in application models.
Reusable Applications
Self-contained package of code that encapsulates a specific functionality.
- can be shared across projects without requiring extensive modifications.
Reason for reusable
Modularity
- modular and independent
- developed, tested, and maintained separately
Code Reusability
- Reused in multiple projects
- reduces development time by eliminating need to rewrite
Standardization
- encourages consistent coding conventions
Community Contribution
- Django’s ecosystem benefits from a wide range of open-source reusable applications.
Maintainability
- Since reusable applications are self-contained, updates and bug fixes can be applied to the application itself without affecting the projects that use it.