Training Menu

PRESENTATION SUR DJANGO, L’ENVIRONNEMENT, L’ARCHITECTURE MVC ET MVT ET L'ARBORESCENCE D'UN PROJET DJANGO

Nogho Belviane
Jan. 7, 2025 · 23.00 min read
0
Development and Programming
PRESENTATION SUR DJANGO, L’ENVIRONNEMENT, L’ARCHITECTURE MVC ET MVT ET L'ARBORESCENCE D'UN PROJET DJANGO

DJANGO

Definition:

Django is an open-source web framework written in Python. It is used to build fast, secure, and maintainable web applications. Django is very popular for projects ranging from simple websites to complex web platforms because it follows a MVC (Model-View-Controller) architecture , or in Django's case, a variation called MTV (Model-Template-View) .

The importance of Django

1. Speed ​​of development: allows you to quickly develop web applications.
2. Security: It helps prevent common vulnerabilities like attacks
3. Flexibility: Django is suitable for many types of projects
4. Comprehensive: It provides built-in tools to manage databases etc.
5. Community Support: Django has a large community and well-detailed documentation.

What is an environment?

A development environment (especially in Python and Django) is an isolated space where you can work on a project without interfering with other projects or global system settings.

It's mainly about using a virtual environment to manage dependencies and avoid conflicts between projects.

The importance of a virtual environment for Django?

1. Project isolation: Each project has its own libraries and dependencies, independent of other projects.
2. Version Compatibility: Allows using different versions of Python or packages in different projects.
3. Ease of management: You can install, uninstall and update packages without affecting the overall system.

Development architectures

1. MVC (Model-View-Controller)

MVC is a software architecture that separates the main concerns of the application into three distinct layers:

Model: Allows you to define the data structure and interact with the database.
View: The user interface.
Controller: The logic that connects the two.

Functioning

1. The user interacts with the View (e.g. clicking a button on a web page).
2. The View sends this interaction to the Controller .
3. The Controller processes the interaction, retrieves or updates data from the Model , and updates the View to display the result.

Development architectures

2. MVT (Model-View-Template)

Django uses an architecture called MVT , which is very similar to MVC. The main difference is that in MVT:

The “Controller” is managed by Django.
The Template is used to display the data.

Functioning

1. Model: Manages data and interaction with the database.
2. View: Contains the business logic and sends data to the Template.
3. Template: Defines the user interface
Why Django uses MVT instead of MVC?
Controller Abstraction: Django automatically handles some Controller tasks, such as URL routing or request/response handling.
Simplicity: MVT allows to focus on models (database), business logic (views) and user interface (templates) without manually managing a complex controller.

Powerful templates: Django includes a template engine that makes it easy to display data dynamically.

The tree structure of a Django project

• The Django project tree is well organized to facilitate code structuring and maintain a clear, modular architecture.

1. Project Root

manage.py :
Main script for interacting with the Django project.
Allows you to launch the server (runserver), perform migrations (migrate), create an application (startapp), etc.

3. Main project folder (project_name/)

 

__init__.py :
Indicates that this folder is a Python package.
settings.py :
Contains project configuration settings (database, installed applications, security, static files, etc.).
urls.py :
Defines the main routes of the application.
wsgi.py :
Script used to deploy the application with a WSGI compatible server (e.g. Gunicorn).
asgi.py :
• Script used for deployment with asynchronous protocols like WebSockets.

3. Applications (app1/)

Each application represents an independent feature or module in your project.

migrations/:
Contains migration files generated by Django to handle schema changes in the database .
admin.py :
Allows you to customize the Django administration interface ( adding models , configuring displays, etc.).
apps.py :
Contains the application configuration.
Example : the name of the application or specific settings .
models.py :
Contains model definitions ( database tables ) .

views.py :

Contains the business logic of the application.

The tree structure of a Django project

wsgi.py :
Script used to deploy the application with a WSGI compatible server (e.g. Gunicorn).
asgi.py :
• Script used for deployment with asynchronous protocols like WebSockets.

3. Applications (app1/)

Each application represents an independent feature or module in your project.

migrations/:
Contains migration files generated by Django to handle schema changes in the database.
admin.py :
Allows you to customize the Django administration interface (adding models, configuring displays, etc.).
apps.py :
Contains the application configuration.
Example: the name of the application or specific settings .
models.py :
Contains model definitions (database tables).

views.py :

Contains the business logic of the application.

 

tests.py :

Used to write unit tests for the application.

 

urls.py (to create):

Defines application-specific routes.

 

templates/ :

Contains the HTML files for this application.

 

static/ :

• Contains static files like CSS, JS or images for this application.

 

 

 
0

Applaudissez pour montrer votre soutien

Nogho Belviane

1 Followers · Writer for Development and Programming