Let’s learn Django (Beginner’s Guide) – Introduction [Part I]



Hello everyone, this is the first part of my tutorial on Django Web Framework. Actually, I started learning Django very recently. But immediately I realized that learning Django is not very hard as other web technologies and I’m loving it. So I wanted to share my knowledge with you all. Hope this will help you.

You may have learned python as your first programming language and if you have begun with something like Java or C then python may be some kindergarten thing to you. So, most of the people didn’t see the real advantages of learning python and they will simply forget it. So, I thought it will be good enough to share these advantages of python and Django. https://worthwhile.com/blog/2016/07/19/django-python-advantages/ . Hopefully, this will differ the way you think.

Django tutorials. Yes!.. There are many tutorials, courses, materials out there to learn Django but I want to share the easiest steps to get started. This tutorial will be beginner friendly and I will use Django on windows.

In this part, I will do a brief introduction on Django and the design pattern that use in Django. So let’s get started!

What is Django?

Django is a high-level python web framework and it is Free and Open Source as most of the web frameworks. Django encourages rapid application development and follows MTV design pattern (Model – Template -View) which I will discuss later. When considering other python web frameworks such as Tornado, Pyramid and Flask, Django (High-level python framework) is good for beginners.

Benefits of Django
  • ·         Help Rapid development
  • ·         High performance
  • ·         Full-featured (It has functionalities such as User authentication, RSS feeds, administration, site maps)
  • ·         Very Secure (Protects you from  SQL injection, cross-site scripting attack, cross side fraudary)
  • ·         Scalability is high – Django can handle lots of traffics.
  • ·         Versatile framework – Using Django, you can make all kinds of diverse applications ( such as social networks, content management systems to scientific computing platforms)

Sites that use/used Django

These are some of the popular sites which are using django


You can find more details from here.

Design pattern (MTV)

MTV is similar to MVC concept and slightly modified version of MVC.

In MTV, M represents Models, T represents Templates and V represents Views.
  • ·         Model (Data Access layer) – Anything to do with the interacting, relating and validating data will be done here.
  • ·         Template (Presentation layer) – Manage all Presentation-related decisions
  • ·         View (Business Logic layer) – Access the model and displays the appropriate template (Works as the controller in MVC). And this is known as the Bridge between Model and Template.




Controller ‘C’ is handled by the framework itself. The component that acts as the controller is called ‘URL Dispatcher’.

Django Architecture

The URL dispatcher maps the requested URL to view function and calls it. The views function performs the requested action, which typically involves reading or writing to the database. It may include other tasks as well.

If caching is enabled, the view function can check to see if a cached version of the pages exists and bypass all further steps, returning the cached version, instead.

After performing a requested tasks, the view returns an HTTP response object (usually after passing the data through a template) to the web browser. Optionally, the view can save a version of the HTTP response object in the caching system for a specified length of time.

Concept of apps

Single project/website on Django can contain multiple “apps”. For an example see the following diagram.



If you have multiple apps in your project, you can move one app to another project easily or you can use other people’s apps in your project also. And yes, you can have a single app on your website or project too. Read more.

That’s all for now. In the next section, I will teach you How to install python and Django, How to set up the environment and how to get started with a new application using Django. Till then Good Luck.

Kalpani

Comments