What is Django?
This is the common question for newbie as well as experienced developers: what Django actually is?
So Django is a Python-based free and open-source web framework that follows the model–template–views (MTV) architectural pattern.
Django is a high-level Python web framework that enables rapid development of secure and maintainable websites.
Why do we need it?
As django is free open source web framework thus it is maintained by many experienced developers,
It takes care of much of the hard work of web development, so you can focus on writing your app more precisely.
Django has built in modules so we don’t need to write it manually, except if you want to modify it as per your need.
It has many features like; SEO optimized, High Security, High Scalability, Rapid development, Excellent Documentation, Thoroughly Tested, Versatile in Nature, Vast and Supported Community and of course it is a python web framework. We‘ll see the details later in this blog.
What are the benefits of using django?
With the use of django framework you can build robust, secure and highly customized sites.
Everything depends on the Django ORM, whether it’s front-end stuff or backend.
All components get deployed together without any corruption.
What Makes Django Different From Others?
The main goals of the Django web framework are innocence, versatility, dependability, and scalability, security.
Django provides many built-in modules so we don’t need to write it manually every time.
Thus this makes it different from other frameworks.
Why Developers Prefer Django Web Framework?
If you are a Python developer, then you will be aware of the importance of remodeling an existing website into another form
It is easy to remodel your existing website to the Django framework if you have developed it using Python.
Even then, it is easy because Django manages to integrate with any new technology that correlates to web app development.
Here are some famous companies/agencies who use the Django framework,
Instagram, Mozilla firefox, Pinterest, Nasa, Spotify, YouTube, RobinHood, Reddit, bitbucket, National Geographic, The Washington Post, Eventbrite, Disqus, Prezi
Practical:
Before we jump into practical there are some prerequisites, you must have an understanding of OOPs concepts and python programming,
In this section, we’ll see a simple web app overview using Django framework,
Find the installation guide, click here!
After installation of python, pip, and Django,
Write in the terminal;
Go to the project folder then create an application by using this command,
You’ll see directory structure something like this,
In settings.py, you’ll find the main components of the project, one project may have multiple applications.
urls.py file has all the URL routes for the applicationsmodels.py file have all the models of the application, basically, this file represents the tables of the project And after that views.py file have views of the application you can write your logic in this file So, now first thing first Now we perform migrations by using these commands
These will apply the migrations into the database.
Now let’s create out admin user by using this command
These commands will create an admin user
Now, let us run our application by using this command to check if there are any issues.
Now go to the port http://127.0.0.1:8000/
You should see this output
Now we good to go,
In testapp/views.py file write,
create testapp/urls.py file and write,
And now let’s include these URLs into the testproject/urls.py,
Now refresh the output,
If you go to the route of http://127.0.0.1:8000/about/ you’ll see about page and just like that if you go to the route of http://127.0.0.1:8000/contact/ you’ll see contact page
And if you goto the route of http://127.0.0.1:8000/admin/
After login, you’ll see Django built-in admin panel
And Bingo your first Django Web app is ready! Now you can customize the site as per your need, you can also use templates and static files like HTML, CSS, JavaScript, text files, etc.
For further information kindly refer to the official Django documentation.
WhatsApp us