Python Flask index.html模板继承问题

问题描述 投票:-1回答:2

我正在尝试使用模板继承,以便我的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>

pycharm jinja2 syntax-highlighting
2个回答
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


0
投票

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

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

至:

{{url_for( '索引')}}

© www.soinside.com 2019 - 2024. All rights reserved.