Django
Table of contents
Before defining the Django Framework, let's first understand what a framework is. A framework is a conceptual structure that serves as a guide for the building of something that expands the structure into something useful. In simple words, the framework is a combination of specific components and packages, which are some sort of ready-made things to work with when building complex applications to make our task easier. Now it's time to understand what Django is.
Django is a free and open-source web framework used to create websites using Python. It is a back-end server-side web framework. It has many built-in features like a login system, database connection, and CRUD (Create, Read, Update, Delete) operations. It emphasizes the reusability of code and components, also called "Don't Repeat Yourself.".
How does Django work?
It works on the model, view, and template design. The model basically means data from a database. The view is a request handler that returns the relevant template and content based on the request from the user, and template means a file such as name.html, style.css, etc. containing the layout of the web page, with logic on how to display the given data or file...
Model
The model provides data from the database. As we all know, the most common and popular way to extract data from a database is through SQL, but to work with SQL, we need to have a pretty good understanding of database structure, which is very difficult for all of us. So to work with databases, Django provides an object-relational mapping (ORM) technique to deliver the data without having to write too many complex SQL statements. The model is located in the models.py file of any application in the Django project.
Views
Views are the functions that take HTTP requests as arguments and return the final result. In between, it also imports models and processes what data to send to the template. Views are located in the views.py file.
Template
A text file where you describe what should be displayed and how the result should be represented. It includes .html files, which show the layout of the webpage. The templates for an application are located in the template folder.
URLs
Django also provides a way to navigate through the pages of the website. It can be done in the file URLs.py
How can Django be installed and used on Windows?
Django requires Python. So, Python must be installed with the package manager pip on our computer. In this article, it is assumed that we have installed the latest version of Python and created a virtual environment. With the given steps, we can use Django on our computer:
Write the following command in cmd to install Django: pip install Django
.After the successful installation of Django, write the following:
Command : django admin startproject Project_Name With this command, we have created a project named Project_Name with the following files: psychache, init.py, asgi.py, settings.py, urls.py, wsgi.py, db.sqlite3, manage.py, etc.Now all we need to do is use the following command after
going into the project folder directory: python manage.py runserverCopy the URL like this one : (http://127.0.0.1:8000/) from the
command prompt, which we will get after executing the above
command. Now we will go to Chrome, paste the URL, and hit enter.This is how we can successfully run our first server.
In a nutshell, I would like to throw out a few reasons why Django is the first choice when it comes to web development.
Backward Compatibility: It offers the provision of working with its older versions and making use of its older formats and features.
Community Support: Having a large community has benefits of its own, and Django enriches it.
Infrastructure: Django is independent and does not require any external solution It is everything from an ORM to a web server. Simple: Django is very simple to use, and its documentation is excellent and unique.
To summarize, Django helps developers compose custom web applications in Python by offering many features and modules. Currently, Django is being rehearsed by various high-traffic websites like Google, YouTube, Pinterest, Spotify, and Instagram. However, Django, like other web systems, has its own pros and cons.
Subscribe to my newsletter
Read articles from Soniya Prasad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Soniya Prasad
Soniya Prasad
I am a developer from India.