jinja2如何扩展jquery内容的html模板?

ldioqlga  于 2023-01-25  发布在  jQuery
关注(0)|答案(3)|浏览(194)

下面是我的html代码

    • 基本. html**
<title> {% block title %}{% endblock %} </title>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav mr-auto">
            
            
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Dropdown
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                <a class="dropdown-item" href="/content">Home</a>
                <a class="dropdown-item" href="#">Calendar</a>
        
              </div>
            </li>
            <li class="nav-item">
              <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Still in progress...</a>
            </li>
          </ul>
    
          </form>
        </div>
      </nav>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>

这是我的jquery代码:

    • 索引. html**
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<title>Datepicker</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/2.14.1/moment.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>


<script>
  $(function () {
    $('#datetimepicker1').datetimepicker();
 });
</script>
<body>
    
<div class="container">
   <div class="panel panel-primary">
      <div class="panel-heading">Schedule an Appointment</div>
        <div class="panel-body">
            <form action="/ok" method="post">
                <div class="row">
                    <div class='col-md-6'>
                        <div class="form-group">
                        <label class="control-label">Appointment Time</label>
                            <div class='input-group date' id='datetimepicker1'>
                                <input type='text' class="form-control" name="Time"/>
                                <span class="input-group-addon">
                                    <span class="glyphicon glyphicon-calendar"></span>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
                <input type="submit" class="btn btn-primary" value="Submit">
            </form>
        </div>
    </div>
</div>
</body>

我试过很多次修改index.html使其可以被base.html扩展,但是都失败了,chrome中不仅不能改变背景色,也不能加载jquery,所以没有datetimepicker出现,我怎么用{% extends "base.html"%}(jinja2方法)把base.html扩展成index.html呢?非常感谢

jucafojl

jucafojl1#

首先你要定义
{% block content %}{% endblock %}
在base.html中,然后在index.html中。
{% extends "base.html" %} // at top of file
所有内容应介于
在index.html中的{% block content %}{% endblock %}。您可以在documentation中看到

n3h0vuf2

n3h0vuf22#

base.html

<html> ...

your_main_html.html

{% extends "base.html" %}

{% block extrahead %}
<style>
     <!-- your css codes -->
</style>
{% endblock %}

{% block content %}
<!-- your html and jinja codes -->
{% endblock %}

{% block extrajs %}
 <script>
    <!-- your js codes -->
 </script>
{% endblock %}
uinbv5nw

uinbv5nw3#

您将需要从https://jquery.com/download/下载jQuery js文件,并在head标记内的索引文件中使用该文件
<script src="jquery-3.6.1.min.js"></script>
或者使用jQuery CDN,如下所示
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>

相关问题