Python Django Tutorial: Use Of Templates - Part Seven

Today, I will share one new part of Python Django from my tutorial series. In this part you will learn the how to use html template with django.

I already told you the following:

Django has many built-in tags and filtesr for using in templates with django. Each tag and filter gives many facilities to show results on webpage. It almost works as angularjs doe sbut It can’t work on run time. It works only when It loads the content the  first time. But when it loads the first time it has same features as angularJs.

Now today I want to show how can you use built-in templates html pages in django also some basic built in tag uses with templates.

  1. Now create django project and after that create django app in project.

  2. After that create new folder in django app folder and make html file in this folder.


  3. Now we create model in file as below.


  4. Migrate this models. If you don’t know then follow my previous articles.

  5. After that we go to file to use this model in admin for entering value into this table of database.


  6. Now open admin panel and insert value in Publisher models.

  7. Now we want show all values in our templates. So now we go to files of django app that define urls.


  8. Now we go to for access templates and send table data to templates using view file.

  9. We create method in file as below image:

  10. Here publisher variable holds the all value of publisher table and ‘templates/first.html’ denotes location html file.’publisher’:publisher is context that we use in templates ofr accessing data fro this context type variable.

  11. Now we go to first.html file and write code as below.


  12. In this code for loop is used for accessing each row from publisher object. In, is attributes of table.

    Note: Attribute name in templates is always same as the attributes.

  13. Now go to url Here you will get all data from database in print in webpage.


So this is the basic html page use. Django has various types of facilities to use html pages according to your needs and has many facilities using built –in tags.


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now