Python Flask index.html模板继承问题

时间:2019-02-21 02:53:48

标签: pycharm jinja2 syntax-highlighting

我正在尝试使用模板继承,以便我的index.html页面可以使用base.html页面。问题是我的PyCharm客户端似乎无法识别extends标记(例如base.html不是粗体)。

{% extends "base.html" %}

{% block title%}
Thermos-welcome
{% endblock %}

enter image description here

我应该期待这样的事情 enter image description here

index.html文件

{% extends "base.html" %}

{% block title%}
Thermos-welcome
{% endblock %}

{% block content %}
            <article>
                <header>
                    <h1>Data Quality</h1>
                    <p>To understand and measure</p>
                </header>
            </article>
{% endblock %}

base.html

<!doctype html>
<html class="no-js" lang="">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title> {% block title %}{% endblock %}</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="../static/css/normalize.min.css">
    <link rel="stylesheet" href="../static/css/main.css">

    <script src="../static/js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
</head>
<body>

    <div class="header-container">
        <header class="wrapper clearfix">
            <a href="{{url_for('index.html')}}"></a> <h1 class="title">ENTERPRISE DATA QUALITY</h1>
            <nav>
                <ul>
                    <li><a href="{{ url_for('add') }}">Add user</a></li>
                    <li><a href="#">Data Marketplace</a></li>
                    <li><a href="#">Data Maestro</a></li>
                </ul>
            </nav>
        </header>
    </div>

    <div class="main-container">
        <div class="main wrapper clearfix">

            {% block content %}
            {% endblock %}

            {% block sidebar %}
                <aside>
                    <h3>aside</h3>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sodales urna non odio egestas tempor. Nunc vel vehicula ante. Etiam bibendum iaculis libero, eget molestie nisl pharetra in. In semper consequat est, eu porta velit mollis nec. Curabitur posuere enim eget turpis feugiat tempor. Etiam ullamcorper lorem dapibus velit suscipit ultrices.</p>
                </aside>
            {% endblock %}

        </div> <!-- #main -->
    </div> <!-- #main-container -->

    <div class="footer-container">
        <footer class="wrapper">
            <h3>footer</h3>
        </footer>
    </div>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="../static/js/vendor/jquery-1.11.2.min.js"><\/script>')</script>

    <script src="js/main.js"></script>
</body>

2 个答案:

答案 0 :(得分:1)

很遗憾地报告PyCharm Community Edition不支持您期望的突出显示模板。您需要升级到PyCharm Professional才能使用此功能。

在这两个地方都注明了

https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html

在这里:

https://www.jetbrains.com/help/pycharm/defining-template-directories.html

答案 1 :(得分:0)

在我的base.html文件中-我需要更改以下行

{{url_for('index.html')}}

收件人:

{{url_for('index')}}