简体   繁体   中英

Flask html templates inheritance issue - mixed elements

everyone! I have an issue when inheriting from another template in Flask. My first file layout.html looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Flask</title>
    <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
    <script type="text/javascript" src="script.js"></script>
</head>
<body>
    <header>
        <h1>Some header</h1>
    </header>
    <content>
        {% block content %}{% endblock %}
    </content>
</body>
</html>

Second one "main.html":

{% extends "layout.html" %}

{% block content %}<p>test</p>{% endblock %}

Everything looks ok but when I load the page in browser the elements looks like this(everything from head is moved to body:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<meta charset="UTF-8">
<title>Flask</title>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<script type="text/javascript" src="script.js"></script>
<header>
        <h1>Some header</h1>
</header>
<content>
    <p>test</p>
</content>
</body>
</html>

Can anyone explain why this happens?

Maybe a little bit too late... The issue was, that I'd changed my IDE. Before I'd used PyCharm, then I switched to Visual Studio. It looks like they both use different encoding and something broke during migration. Creating new file and copying content was the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM