In some cases, writing perspectives, as we've got seen in advance is genuinely heavy. Imagine you need a static web page or a listing page. Django gives a clean way to set the ones simple perspectives this is called universal views.
Unlike conventional views, general views are training not functions. Django offers a fixed of training for customary views in django.perspectives.widely wide-spread, and each universal view is one of those classes or a class that inherits from certainly one of them.
There are 10+ generic lessons –
This you may use for your conventional view. Allow examine a few example to see how it works.
Let’s submit a static web page from the “static.html” template.
Our static.html –
If we did that the manner we learned before, we might need to change the myapp/perspectives.py to be –
and myapp/urls.py to be –
The great manner is to use common views. For that, our myapp/perspectives.py becomes –
And our myapp/urls.py we will be –
When accessing /myapp/static you will get −
For the same result we also can, do the subsequent −
As you may see, you simply want to exchange the url.py record in the second method.
We are going to list all entries in our Dreamreal model. Doing so is made clean through the usage of the ListView time-honored view magnificence. Edit the url.py report and replace it as –
Critical to be aware at this factor is that the variable bypass through the time-honored view to the template is object_list. in case you need to name it yourself, you'll need to add a context_object_name argument to the as_view approach. Then the url.py becomes −
The associated template will then be −
Accessing /myapp/dreamreals/ will produce the following page −
Django Related Tutorials
|Python Tutorial||Java Script Tutorial|
|PHP Tutorial||Ruby on Rails Tutorial|
|XHTML Tutorial||Apache Solr Tutorial|
Django Related Interview Questions
|Python Interview Questions||Java Script Interview Questions|
|Ruby on Rails Interview Questions||Ruby Interview Questions|
|MongoDB Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.