首頁  >  問答  >  主體

python - django模板 include模板的数据问题

如:views.py返回是return render(request, 'index.html')
而index.html内容是:

 {% include 'header.html' %}

然后header.html的内容可以是动态的吗?怎么写,谢谢!

{{text}}
PHP中文网PHP中文网2741 天前525

全部回覆(1)我來回復

  • ringa_lee

    ringa_lee2017-04-18 10:31:00

    header可以是動態的,但是動態的變數需要render時渲染出去.
    如:

    • header.html

    <script src="{{ static_url('js/common.js') }}" type="text/javascript" charset="utf-8"></script>
    <p class="header">
       {{ user.username }} 
    </p>
    • index.html

    <html>
    <head>
    </head>
    <body>
        {% include "header.html" %}  <!--包含了header.html的代码-->
        ...
    </body>
    </html>

    回覆
    0
  • 取消回覆