[英]Flask html templates inheritance issue - mixed elements
大家! 從Flask中的另一個模板繼承時,我遇到問題。 我的第一個文件layout.html看起來像這樣:
<!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>
第二個“ main.html”:
{% extends "layout.html" %}
{% block content %}<p>test</p>{% endblock %}
一切看起來都不錯,但是當我在瀏覽器中加載頁面時,元素看起來像這樣(從頭到腳的所有內容都移到了主體上:
<!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>
誰能解釋為什么會這樣?
也許為時已晚...問題是,我改變了我的IDE。 在使用PyCharm之前,我切換到了Visual Studio。 看起來他們都使用了不同的編碼,並且在遷移過程中出現了問題。 解決方案是創建新文件並復制內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.