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)

django-模板之comment标签(六)

 

相关文章:

  • 2021-11-14
  • 2022-12-23
  • 2021-11-27
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2021-10-01
猜你喜欢
  • 2021-08-16
  • 2020-07-23
  • 2019-03-13
  • 2022-12-23
  • 2021-04-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案