django-模板之comment标签(六)

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{title}}</title>
    <style>
        .header {
            height: 50px;
            background-color: fuchsia;;
        }
        .content{
            height:300px;
        }
        .footer{
            height:50px;
            background-color: thistle;
        }
    </style>
</head>
<body>
    <div class="header">Nav Area</div>
    <div class="content">
        {% for letter in letters %}
         {
% comment %} <h1>{{letter}}</h1>        {% endcomment %} <h1>{{letter}}</h1> {% endfor%} {% block content %} {% endblock %} </div> <div class="footer">Foot Area</div> </body> </html>

comment标签用于注释

for标签用于读取列表并显示。

book/views.py

from django.shortcuts import render

def index(request):
    requests={
        'letters':['a','b','c','d']
    }
    return render(request,"index.html",context=requests)

原文地址:https://www.cnblogs.com/xiximayou/p/11747368.html