Django create view template

The above content creates a view and URL for my blog referencing program. Next, I will add a template and display the post in a user-friendly way.

Next, create the following directories and files in the blog application directory:

templates/
     blog/
           base.html
   post/
        list.html
       detail.html

The above structure will represent the file structure of the template. Among them, the base.html file contains the main HTML structure of the site and divides the content into the main content area and sidebar. The list.html and detail.html files are inherited from the base.html file and are used to render the blog post list and detailed view respectively.

Django includes a powerful template language and can determine how the data is displayed. The language is based on template tags, template variables, and template filters, as follows:

The template tag is responsible for controlling the rendering of the template, like {% tag %}
When the template is rendered, the template variable is replaced with the corresponding value, like { {variable }} The
template filter can adjust the variable for the display, like { {variable | filter }}
Readers can visit https://docs.djangoproject.com/en/3.0/ref/templates/builtins/ to view all the built-in template tags and filters.

The following editing of base.html and list.html and detail.html needs to be done by readers, so I will not show them here.

The function of {% load static %} is to notify Django to load the static template tag provided by the django.contrib.staticfiles application, which is located in the INSTALLED_APPS setting item.

The function of {% extends “blog/base.html” %} is to inform Django to inherit the blog/base.html template.

After everything is complete, readers can return to the browser to refresh and click on the post title to see a detailed view of the post.

Thank you for your review and support.

Guess you like

Origin blog.csdn.net/Erudite_x/article/details/112725093