Users Online

· Guests Online: 42

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

Articles Hierarchy

Django Tutorial

Django Framework

Introduction to Django Framework

Django is a Python-based server-side web framework used worldwide to make web applications. Some of the top companies using Django are:

  • NASA
  • Google (Youtube)
  • Instagram
  • MIT

Since Django employs Python, we can deploy regular websites and Machine Learning Models, such as for Speech Recognition, Fraud Detection, etc., over the web. Django has a very modular approach called MVT (Model-View-Template) architecture. Following this architecture makes the code very easy to develop, deploy and maintain.

Django also provides a built-in Admin module that can be used to store master values on the website. For example, for processing a Loan application, there may be a screen called “New Loan” then in this form, suppose there is a drop-down menu for Loan Types, Personal Loan, Car Loan, Home Loan, etc., then these values are maintained through the admin panel.

django-framework

Understanding Django Framework

As we know that Django has an MVT architecture, we will go step by step in explaining each term.

The moment we install the Django framework and create a new project, the following files (the most important and frequent) are automatically created for us to write our code :

  • models.py
  • views.py
  • settings.py
  • urls.py

Each of these files is intended for code modularity. settings.py file stores all the custom configurations, such as database connection parameters, server details on which the application will be hosted, global variables that can be accessed throughout the application, etc.

urls.py file has a list of all the custom URLs which will be used in the application to access different pages. Let us look at the models, views, and templates.

Django framework and create a new project

Model

Model in Django refers to Database Tables created per the requirements to store data. For example, if we want to create a Bank website, then we need tables to store customer data such as Customer Name, Account Number, Bank Balance, etc. The code for writing these models is put into the models.py file.

Now you may wonder which database to use for creating Django Models. Relax! Django supports all major databases (Oracle, PostgreSQL, MS SQL Server, MySQL ), and you need not worry about different types of SQL for different databases. Because Django implicitly can translate your Python code into corresponding Database SQL.

View

View in Django refers to what needs to be done/processed over the requests received from the client to the server. These HTTP requests (GET, POST, etc.) can be for specific purposes such as Account Debit, Account Credit, Creating a new account, etc.

Views, in turn, interact with models to store/retrieve/delete data. The code for writing these views is put into views.py

Template

Templates refer to the HTML pages which the user sees. It contains the background images, TextBoxes, Buttons, etc., which are rendered in the client’s browser and gives the website a look and feel.

Templates don’t have a .py file because templates are HTML codes. Hence, we have to make a templates folder and keep all the .html files in this folder.

Why Use Django?

Django is popularly known as a “Web framework for perfectionists with deadlines.” This is a very apt saying because all the components you may require to build a web application come bundled with this framework viz., in-built web server and SQLite Database. Also, the admin panel prevents reinventing the whole wheel, and the developer can focus on writing the core application code rather than creating basic necessities.

The other most important feature of Django is “SECURITY.” Django forces the developer to implement security-related features into the application; otherwise, the code does not execute successfully. For example, csrf (Cross-Site Request Forgery). csrf is a random token generated every time we submit form data. The Django server validates this token on every HTTP POST Request it receives. If some hacker tries to attack, then this token becomes invalid and our application remains secure.

Another interesting feature of Django is – Template extensions and Tags. Django provides with tons of template tags that can be used directly in the templates (.html codes), thus preventing development effort and reducing the size of templates. One template (for ex: base.html) can be easily extended into another template, and as a result, this other template reduces to only a few lines of HTML code.

Importance of Django Framework

Until now, you must have got a fair idea of how Django can be so useful. The importance of Django can be realized from the fact that the world’s top companies use Django for their application. This includes Mozilla, NASA, Instagram, Pinterest, Dropbox, and many more. The market is full of Django opportunities, yet only a few people are available; hence Django people easily get the upper hand.

Moreover, cloud service providers such as AWS have a dedicated service to host Django applications called Elastic Beanstalk which provides managed Apache server, PostgreSQL, Load Balancer, and AutoScaling for Heavy Load applications. Django applications can also be exposed as APIs for consumption by Third Party Software. This is done by using the Django REST Framework.

Django Prerequisite

Python is the single most important prerequisite for learning Django. More specifically, Concepts related to Class, Inheritance, Functions, and Data Structures (Lists, Dictionaries, Tuples) should be very clear because the entire Django framework revolves around Classes and Functions.

Also, to develop the front-end (Templates section), knowledge of HTML, Javascript, and AJAX will greatly help. To install Django, you need your Computer with Linux/Windows with Python installed. Then with a single command (pip install Django), Django becomes your playground.

Conclusion

Django is extremely rapid in development, scalable and flexible in design, and highly secure and reliable. The vast Django community solves any problem you might face during Django development. If you practice and master the basic concepts of Django, then you can build Production-Ready web applications in a matter of a few days.

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.90 seconds
10,842,812 unique visits