Technology Sharing

Django in Depth (Part 4)

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Django template system

introduction

In the previous few days, we introduced the basic concepts of Django, models and views. Today we will explore Django's template system, which is responsible for combining data and HTML templates to generate content that end users see.

Overview of Django's template system

Django's template system is a powerful tool for inserting dynamic data into static or semi-static pages. It uses its own template language that allows you to embed Python code in HTML.

Create a template

  1. Create a template file: In your Django application directory, create atemplatesDjango will automatically look for template files in this folder.
  2. myapp/├── templates/ │ └── base.html └── ...
  3. Writing Templates:existtemplatesfolder, create an HTML file and write your template.
  4. DOCTYPE html