Learn Cave provides you best and easy learning tutorials, projects from scratch and developing programming skills from basics with user friendly lessons, Learning is only hard untill you are BEGINNER!
We provide Co-Curricular events for college students can explore our knowledges to outside of campus
By Learn Cave Team
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Django makes it easier to build better web apps quickly and with less code.
Django comes with the following design philosophies
Django aims to make each element of its stack independent of the others.
Less code so in turn a quick development.
Django aims to make each element of its stack independent of the others.
Django's philosophy is to do all it can to facilitate hyper-fast development.
Django strictly maintains a clean design throughout its own code and makes it easy to follow best web-development practices.
As you already know, Django is a Python web framework. And like most modern framework, Django supports the MVC pattern. First let's see what is the Model-View-Controller (MVC) pattern, and then we will look at Django’s specificity for the Model-View-Template (MVT) pattern.
When talking about applications that provides UI (web or desktop), we usually talk about MVC architecture. And as the name suggests, MVC pattern is based on three components: Model, View, and Controller. Check our MVC tutorial here to know more.
The Model-View-Template (MVT) is slightly different from MVC. In fact the main difference between the two patterns is that Django itself takes care of the Controller part (Software Code that controls the interactions between the Model and View), leaving us with the template. The template is a HTML file mixed with Django Template Language (DTL).
A view function, or “view” for short, is simply a Python function that takes a web request and returns a web response. This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image, etc. Example: You use view to create web pages, note that you need to associate a view to a URL to see it as a web page.
In Django, views have to be created in the app views.py file.
We will create a simple view in myapp to say "welcome to my app!"
In this view, we use HttpResponse to render the HTML (as you have probably noticed we have the HTML hard coded in the view). To see this view as a page we just need to map it to a URL (this will be discussed in an upcoming chapter).
We used HttpResponse to render the HTML in the view before. This is not the best way to render pages. Django supports the MVT pattern so to make the precedent view, Django - MVT like, we will need −
A template: myapp/templates/hello.html
from django.shortcuts import renderViews can also accept parameters −
from django.http import HttpResponseLearn Cave helps you to get close to your dreams of Programming world. Learn Cave is one of the best online coding Learning platform for programmers in whole wide world. Beginner's who want to learn Coding and Programming are too joining us. We have around
With our comprehensive course curriculum, you will cover all cutting edge topics. Learn Cave has it's own brand, with TAG of Asia's Biggest Online Coding Course. With the evolution of computers programming languages, Learn Cave is also contributing in this evolution by provind paid courses of Programming Languages such as Python, Javascript, C++, Java, Angular and more. We help students to fast-track your career in this evolving programming field.
Yes, our courses are too friendly to get understood easily for freshies in programming.
Subscribe our Learn Cave Youtube to get instant updates of codefest. You can also join Our Discord Server for more information.
Learn Cave provides you 24/7 Guidence in programming courses. Users get free source code of many websites for Professional/Advance Learning.
© Created By Learn Cave 2023