Source: Internet
Author: User
Tags install django

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/

 from Import Render def Blog (request):      #第一个参数必须有 (generally called request)      return ' blog/blog.html ')    

Jinja Basic Syntax examples


<doctype html>
{% block title%} <!-blocks that can be replaced in subclasses
<% 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 '%}" >
{% block content%} <!-blocks that can be replaced in subclasses
{% Endblock%}


{% 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 {{} = = ' Zoro ' %} use of <!-variable
<p>{{|date: "y-m-d"}}</p> <!-using filters,
{% ENDIF%}
{% Endblock%}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.