如何防止Jinja2引擎中的不同部分出现过高?

时间:2019-01-25 21:53:55

标签: html flask bootstrap-4 jinja2

我是Flask的新手,我已经阅读了相关的问题,但是我仍然不知道如何解决此问题,因此我们将不胜感激。请不要重复这个问题。

我有以下文件:

index.html

{% extends "bootstrap/base.html" %}

{% block styles %}

<!-- Bootstrap core CSS -->
<link href="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

<!-- Custom fonts for this template -->
<link href="/static/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">


<!-- Custom styles for this template -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/static/css/agency.css">
<link rel="stylesheet" type="text/css" href="/static/css/agency.min.css">

{% endblock %}

{% block navbar %}

<body id="page-top">

  <!-- Navigation -->
  <nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="mainNav">
    <div class="container">
      <a class="navbar-brand js-scroll-trigger" href="#page-top">RFJI Protein Database</a>
      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
        Menu
        <i class="fas fa-bars"></i>
      </button>
      <div class="collapse navbar-collapse" id="navbarResponsive">
        <ul class="navbar-nav text-uppercase ml-auto">
          <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="{{ url_for('upload')}}">Upload File</a>
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#">Protein Database</a>
          </li>
          </li>
          </li>
          </li>



          <div class="wrap">
            <div class="search">
              <div class="col-lg-11 text-center">
              <input type="text" class="searchTerm" placeholder="What are you looking for?">
              <button type="submit" class="searchButton">
                <i class="fa fa-search"></i>
              </button>
            </div>
          </div>

        </ul>


{% endblock %}

{% block content %}


              <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>

    </style>
    </head>
    <body>
          </div>
        </div>
      </nav>

    <header class="masthead">
      <div class="container">
        <div class="intro-text">
          <div class="intro-lead-in">Welcome to the RFJI Protein Database!</div>
          <div class="intro-heading text-uppercase">It's Nice To Meet You</div>

    <style>
    font-family: Arial;
    </style>

    {% endblock %}

    {% block body %}
    <!-- Services -->
    <section id="services">
      <div class="container">
        <div class="row">
          <div class="col-lg-12 text-center">
            <h2 class="section-heading text-uppercase">Features</h2>
            <h3 class="section-subheading text-muted">Lorem ipsum dolor sit amet consectetur.</h3>
          </div>
        </div>
        <div class="row text-center">
          <div class="col-md-4">
          <img src="/static/img/kinase.png" alt="Girl in a onci" style="width:80px;height:90px;">

            </span>
            <h4 class="service-heading">Search Kinases</h4>
            <p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima maxime quam architecto quo inventore harum ex magni, dicta impedit.</p>
          </div>
          <div class="col-md-4">
          <img src="/static/img/inhibitor.png" alt="Girl in a onci" style="width:80px;height:90px;">
            </span>
            <h4 class="service-heading">Search Kinase Inhibitors</h4>
            <p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima maxime quam architecto quo inventore harum ex magni, dicta impedit.</p>
          </div>
          <div class="col-md-4">

          <img src="/static/img/upload.png" alt="Girl in a onci" style="width:80px;height:90px;">
            </span>
            <h4 class="service-heading">Import your own dataset</h4>
            <p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima maxime quam architecto quo inventore harum ex magni, dicta impedit.</p>
          </div>
        </div>
      </div>
    </section>

    {% endblock %}

问题在于Jinja2引擎仅显示“服务”部分,而忽略其他所有内容。我该如何解决?我添加了一张有关我希望网站看起来如何的图像。

How I want the website to look like

非常感谢,

莫西

1 个答案:

答案 0 :(得分:0)

乍一看,整个模板一团糟。

  • 应将其完全删除,因为它不属于模板的中间部分
    <style>
    font-family: Arial;
    </style>
  • 有多个<body>标签。在正确的语法中,应该只有1个<body>标记,它可能应该是base.html模板的一部分。在该文件的末尾,还应显示相应的</body>标签。

  • 某些<div>标签未正确关闭。

您确实需要回过头来重新布置此模板,以便每个Jinja2 {% block something %} {% endblock %}节包含一组完整的标签(例如,完整的bootstrap div容器块,该块在endblock语句之前已正确关闭。

在Jinja2文档中,模板继承为described fully。我假设您已经从其他地方剪切并粘贴了此模板的各个部分,只要您确保源引导模板的重要组件没有在错误的位置分开,这都是没有问题的。