
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>模板 &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../genindex.html" />
    <link rel="search" title="搜索" href="../../search.html" />
    <link rel="next" title="Django 模板语言" href="language.html" />
    <link rel="prev" title="信号" href="../signals.html" />



 
<script src="../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="../signals.html" title="信号">previous</a>
     |
    <a href="../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="language.html" title="Django 模板语言">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-templates-index">
            
  <div class="section" id="s-templates">
<span id="templates"></span><h1>模板<a class="headerlink" href="#templates" title="永久链接至标题">¶</a></h1>
<p>Django 的模板引擎提供了一个强大的迷你语言来定义你的应用程序的面向用户层，鼓励应用程序和表现逻辑的清晰分离。任何懂 HTML 的人都可以维护模板，不需要 Python 知识。关于入门材料，请参见 <a class="reference internal" href="../../topics/templates.html"><span class="doc">模板</span></a> 主题指南。</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="language.html">Django 模板语言</a><ul>
<li class="toctree-l2"><a class="reference internal" href="language.html#templates">模板</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html#variables">变量</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html#filters">过滤器</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html#tags">标签</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html#comments">注释</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html#template-inheritance">模板继承</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html#automatic-html-escaping">自动 HTML 转义</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html#accessing-method-calls">访问方法调用</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html#custom-tag-and-filter-libraries">自定义标签和过滤器库</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="builtins.html">内置模板标签和过滤器</a><ul>
<li class="toctree-l2"><a class="reference internal" href="builtins.html#built-in-tag-reference">内置标签参考</a></li>
<li class="toctree-l2"><a class="reference internal" href="builtins.html#built-in-filter-reference">内置过滤器参考</a></li>
<li class="toctree-l2"><a class="reference internal" href="builtins.html#internationalization-tags-and-filters">国际化标签和过滤器</a></li>
<li class="toctree-l2"><a class="reference internal" href="builtins.html#other-tags-and-filters-libraries">其他标签和过滤器库</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="api.html">Django 模板语言：对于 Python 开发者</a><ul>
<li class="toctree-l2"><a class="reference internal" href="api.html#overview">概况</a></li>
<li class="toctree-l2"><a class="reference internal" href="api.html#configuring-an-engine">设置引擎</a></li>
<li class="toctree-l2"><a class="reference internal" href="api.html#loading-a-template">加载模板</a></li>
<li class="toctree-l2"><a class="reference internal" href="api.html#rendering-a-context">渲染上下文</a></li>
<li class="toctree-l2"><a class="reference internal" href="api.html#playing-with-context-objects">使用 <code class="docutils literal notranslate"><span class="pre">Context</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="api.html#loading-templates">加载模板</a></li>
<li class="toctree-l2"><a class="reference internal" href="api.html#custom-loaders">自定义加载器</a></li>
<li class="toctree-l2"><a class="reference internal" href="api.html#template-origin">模板起源</a></li>
</ul>
</li>
</ul>
</div>
<div class="admonition seealso">
<p class="first admonition-title">参见</p>
<p>关于编写自定义标签和过滤器的信息，请参见 <a class="reference internal" href="../../howto/custom-template-tags.html"><span class="doc">自定义模板标签和过滤器</span></a>。</p>
<p class="last">要学习如何在其他 Django 应用中覆盖模板，请看 <a class="reference internal" href="../../howto/overriding-templates.html"><span class="doc">复写模板</span></a>。</p>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="../signals.html"
                        title="上一章">信号</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="language.html"
                        title="下一章">Django 模板语言</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/ref/templates/index.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="../signals.html" title="信号">previous</a>
     |
    <a href="../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="language.html" title="Django 模板语言">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>