Django is a free open source web framework written in the Python language.
A web framework is a
software that is designed to support the development of web applications.A web framework like django
provides the following four basic things:-
URL mapping
Database manipulation
Making templates
Security measures.
Django is a high level Python framework with MVT architect which stands for Model View
Template. This framework gives ready-made components to use and also helps in eliminating
repetitive tasks, makes the development process easy and time saving as it involves less and
simple coding. Applications created with Django are separated in three separate layers: model
(database), view (appearance) and controller (logic), or shortly the model-view-controller (MVC)
architecture.
Advantages of Django
1. Administration GUI-it provides a nice ready to use user interface for administrative activities.
2. Don’t Repeat Yourself (DRY)-Everything should be developed only at one place instead of
repeating it again and again.
3. Secured: Django enables protection against much vulnerability by default, including SQL injection
4. It is designed to be fast, secure and scalable. It comes with an object-relational mapper (ORM),
which means that objects in Python are mapped to objects in a database.
5. Loosely coupled- Django aims to make each element of its stack independent of others.
Django MVC-MVT Architecture
The Model-View-Template (MVT) is slightly different from MVC. Infact the main difference
between the two patterns is that Django itself takes care of the Controller part (Software Code
that controls the interactions between the Model and View), leaving us with the template. The
template is a HTML file mixed with Django Template Language (DTL).
The following diagram illustrates how each of the components of the MVT pattern interacts
with each other to serve a user request −
The developer provides the Model, the view and the template then just maps it to a URL and
Django does the magic to serve it to the user.
How Django works:
1. A request/response system:
2. Web requests enter Django app via URLs
3. Requests are processed by Views
4. Web responses are returned when a user accesses the URL in the browser which is a
HTML page created using Django template system.
To Install Django
set the path in cmd run as administrator
C:\Users\student\AppData\Local\Programs\Python\Python37-32\Scripts>pip install django
Creating project with:
C:\Users\student\AppData\Local\Programs\Python\Python37-32\Scripts>
django-admin startproject project1
C:\Users\student\AppData\Local\Programs\Python\Python37-32\Scripts>cd project1
To start the server
C:\Users\student\AppData\Local\Programs\Python\Python37-32\Scripts\project1>python
manage.py runserver
Creating an app in project1
Now we created a project, we create an app. A project can have many apps.
python manage.py startapp notes
This creates the files:
notes/
init.py
admin.py
migrations/
init.py
models.py
tests.py
views.py
Models: draws a schema of your project's database through python, rather a database
commands itself.
Forms: Method to collect user input data either to process or to store into the project
database.
https://pythonspot.com/django-tutorial-building-a-note-taking-app/
Run the server locally by typing http://127.0.0.1:8000 in web
browser.(Note:minimize the command prompt window as the server should
continue running)