Using Of Django Templates


In the previous chapter, we saw how we can use Django Templates. In this chapter, you will learn how to use an HTML template with Django in the admin interface.

Django Templates

Django has many built-in tags and filters for use in templates with Django. Each tag and filter gives many facilities to show results on the webpage. It almost works as angularjs doe but 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 the same features as angularJs.
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 a Django project and after that create the Django app in the project.
  2. After that create a new folder in the Django app folder and make an HTML file in this folder.
  3. Now we create a model in file as below.
  4. Migrate this model. If you don’t know then follow previous chapters.
  5. After that, we go to the file to use this model in admin for entering the values into this table of database.
  6. Now open the admin panel and insert value in Publisher models.
  7. Now we want to show all the values in our templates. So now we go to files of the 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 all the values of publisher table and ‘templates/first.html’ denotes location of the HTML file. ’publisher’:publisher is the context that we use in templates for 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 the table.
    Note: Attribute name in templates is always the same as the attributes.
  13. Now go to URL Here you will get all data from the database in print on the webpage.
Django has various types of facilities to use HTML pages according to your needs and has many facilities using built-in tags.


In the next chapter, you will learn how to use Django static files. 
Neeraj Kumar
311 8.1k 2.2m
Next » Using Django Static Files