Django Frontend

Django

Django is a framework that can make web applications more accessible and faster. Django is an open-source collection of python libraries, and Django can be used for both the front and back end. The Django Software Foundation maintains the Django framework. The framework is mainly known for the pluggability of its components; that is, its components can fit into any web application. Django uses the reusability of its components method; it is also known as the DRY (Don’t  Repeat Yourself ). Django also provides read, delete and update interfaces which can be used during the runtime of the process and these can be used dynamically. Many websites use the Django framework to create their web applications; some of them include:

  • Instagram
  • Mozilla
  • Clubhouse
  • Nextdoor

Django first came into work in 2003, when two scientists, Adrian Holovaty and Simon Willison, used the python libraries to create the web application. The Django was named after Django Reinhardt, who was aguitarist. In the year 2008, the Django Software Foundation was established, which will now maintain all the properties of Django.

The Django follows the MVT ( Model View template ) design pattern:

Model: The model collects the data from the databases and provides it to the user. SQL is mainly used to extract the data from the databases, but to use SQL, we need to have a greater command of the database structure. In Django, the method the data is delivered to the user with a technique is known as Object Relational Mapping (ORM) technique which is designed mainly to make the work easier. The models are located in the file models.py

View: The view is a kind of function which takes the HTTP requests as an argument, and with this, it will import the required models for the process and returns the data to the template, and it will return the final result. The view is generally located in the file views.py

Template: The templates are generally used to present the final result of the web application. The templates generally use the .html language to design the webpage layout; we can also use the other standard file formats. The templates of the file are usually located in the folder templates.

Django Frontend

To run Django, first, we need to have python installed on our computer, and then we need to check whether the package manager pip is installed or not on our computer. To check them, we need to run the following commands

Command:

python  --version
pip --version

If the python and the pip are already present on your computer, it will return the versions of the python and the pip.

Output:

Python 3.9
pip  18.9.4 from c:\python32\lib\site-packages\pip (python 3.9)

To create a folder of our project and a virtual environment, we need to use the help ofvenv. It will create a virtual environment, and then it will create a  folder “project” with other subfolders like libraries, scripts

Command:

py  -m venv project

Output:

project
    Include
    Lib
pyvenv.cfg

Now we need to activate the virtual environment by using this command:

project\Scripts\activate.bat

Output:

(project)  C:\Users\Nihaas >

Now we need to install Django on our computer with the help of the python install package (pip), with the command:

(project) C:Users\Nihaas >py – m pip install Django

 We can also check the version of python with the help of the following command

(project)  C:\Users\Nihaas>django-admin – version

Output:

3.9.0

 We need to set the name of our project, and then we need to run the following command,

django-admin  startprojectstudentsmarks

Output:

studentsmarks
     manage.py
studentsmarks/
	_init_.py
	asgi.py
	settings.py
	urls.py

Now we need to run our Django packager to check for the working of our browser. We need to go to the /studentsmarks folder, and then we need to execute the command:

py manage.py runserver

Output:       

Watching for file changes with StateReloder
Performing system checks….
System check identified no issues
You have 23  unapplied migrations. Your project may not work properly until you apply migrations for the web application: admin, sessions, auth
Run ‘python.manage.py.migrate’ to apply them
August 31, 2022 – 18:13:22
Django version 3.9.0, using settings ‘students marks.Settings’
Starting development server at http://134.0.1.0:7900/
Quit the server with CTRL-BREAK.

We can find our web application by opening the URL in the new browser in google.