我在烧瓶中有以下模板结构:
templates/
  /posts
    list.html
  base.html
  index.html
我的base.html:
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ITV</title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
    <!-- Latest compiled and minified JavaScript -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</head>
<body>
{%- block topbar -%}
    <nav class="navbar navbar-default navbar-static-top" role="navigation">
      <!-- We use the fluid option here to avoid overriding the fixed width of a normal container within the narrow content columns. -->
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="/">????</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-8">
          <ul class="nav navbar-nav">
            <li class="active"><a href="/">???????</a></li>
            <li><a href="/posts">??????</a></li>
            <li><a href="/schedue">??????? ??????</a></li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </div>
    </nav>
{%- endblock -%}
<div class="container">
    <div class="content">
        {% block page_header %}{% endblock %}
        {% block content %}{% endblock %}
    </div>
</div>
</body>
</html>
我可以渲染模板,例如:render_template('posts/list.html'),它扩展了我的base.html
我的list.html:
{% extends "base.html" %}
{% block content %}
    Posts
{% endblock %}
如何在base.html中设置活动元素菜单
        <li class="active"><a href="/">???????</a></li>
        <li><a href="/posts">??????</a></li>
        <li><a href="/schedue">??????? ??????</a></li>
当我渲染list.html,并且无法将数据直接传递到base.html?
Bur*_*lid 13
在Flask中,默认情况下,request变量在模板中可用,因此您只需签request.path入base.html并调整链接即可.
<li {% if request.path == '/' %}class="active"{% endif %}>
     <a href="/">???????</a>
</li>
| 归档时间: | 
 | 
| 查看次数: | 3817 次 | 
| 最近记录: |