When you install Django, JINJA2 is automatically installed for template rendering.
Static, templates location in project:appname-templates/static-appname
Use just like this:"blog/blog.html","Blog/css/bootstrap.min.css","Blog/img/bg.jpg", Django will automatically go to the respective directory to find the appropriate file
Each app maintains this structure to avoid name collisions
Writing blog/views.py
from Import Render def Blog (request): #第一个参数必须有 (generally called request) return ' blog/blog.html ')
Jinja Basic Syntax examples
<!-basic.html->
<doctype html>
{% block title%} <!-blocks that can be replaced in subclasses
<title>Homepage</title>
<% Endblock%>
<meta charset= "UTF-8" >
{% load staticfiles%} <!-loading and using static files, can also be directly href= ' blog/css/bootstrap.min.css '
<link rel= "stylesheet" type= "Text/css" href= "{% static ' blog/css/bootstrap.min.css '%}" >
<body>
{% block content%} <!-blocks that can be replaced in subclasses
{% Endblock%}
</body>
<!-blog.html->
{% extends "blog/basic.html"%} <!-inherit all content from the basic.html template
{% block title%} <!-replace the contents of the title chunk in the parent class template
<title>my blog</title>
{% Endblock%}
{% block content%}
{% for post in object_list%} Use of <!-for, if
{% If {{Post.name} = = ' Zoro ' %} use of <!-variable
<p>{{post.date|date: "y-m-d"}}</p> <!-using filters,
{% ENDIF%}
{% ENDFOR%}
{% Endblock%}
Django--Templates