【问题标题】:Content of .html file is not displayed when the file extends from another file当文件从另一个文件扩展时,不显示 .html 文件的内容
【发布时间】:2020-10-22 01:13:42
【问题描述】:

我有一个 index.html,我想将其内容扩展到其他页面。如果我将 index.html 扩展到 landing-page.html,则显示来自 index.html 的内容,但来自 的内容login-page.html 不是。

Routes.py

@app.route('/welcome/')
def landing_page():
    return render_template('landing-page.html')

landing-page.html

{% extends "index.html" %}

{% block content %}

  <p>This is from the landing-page</p>

{% endblock content %}

index.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>

当使用/welcome/ 的路由访问landing-page.html 时,输出如下:

从上图可以看出,landing-page.html的内容没有显示出来。我不知道为什么。

【问题讨论】:

    标签: html flask jinja2


    【解决方案1】:

    /welcome 路由运行正常,但两者均未连接。
    还需要 2 个额外的东西:

    1. 扩展功能(并建立连接)
    def landing_page():  
        return render_template('landing-page.html',  
        my_string='FirstInclude')
    
    1. 将包含在 index.html 的某个地方(并因此放置连接)

      {{my_string}}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多