html - 当文件从另一个文件扩展时,不显示 .html 文件的内容
问题描述
我有一个index.html,我想将其内容扩展到其他页面。如果我将index.html扩展到landing-page.html,则会显示index.html中的内容,但不会显示landing-page.html中的内容。
路线.py
@app.route('/welcome/')
def landing_page():
return render_template('landing-page.html')
登陆页面.html
{% extends "index.html" %}
{% block content %}
<p>This is from the landing-page</p>
{% endblock content %}
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"><script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
{% if title %}
<title>Test Title - {{ title }}</title>
{% else %}
<title>Test Title</title>
{% endif %}
</head>
<body>
<p>This is from the index page</p>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
使用以下路径访问landing-page.html 时,/welcome/
输出如下:
从上图中可以看出,landing-page.html的内容并没有显示出来。我无法弄清楚为什么。
解决方案
/welcome 路由运行正常,但两者均未连接。
需要2个额外的东西:
- 扩展功能(并建立连接)
def landing_page():
return render_template('landing-page.html',
my_string='FirstInclude')
将包含在 index.html 某处(并因此放置连接)
<p>{{我的字符串}}</p>
推荐阅读
- asp.net-web-api - 使用特定列表以角度检索数据
- django - 批量创建主对象和同时引用主对象的对象?
- javascript - 提供给图像 React Native 的无效道具源
- shell - 如何测试是否存在与 shell 中环境 yml 文件的确切包描述匹配的 conda 环境?
- mysql - 如何按聚合列过滤非聚合查询结果?
- javascript - 需要一些想法来在 React Native 应用程序中实现异步存储以保持用户登录应用程序
- java - 更新和/或删除时违反 Hibernate H2 参照完整性约束
- scala - 如何在 Play 框架中进行 Flyway 迁移
- ios - 如何处理 FittedBox 中的动态图像
- python - 使用元组从 VBA 列表中删除重复坐标