html - 增加 div 高度以适应里面的内容
问题描述
我正在尝试在网络应用程序中使用select2-bootstrap-theme 。flask
我正在渲染一个使用select2-bootstrap-theme的 HTML 模板。如果我直接打开那个.html
文件。一切都按原样显示,但是当我在运行烧瓶应用程序的情况下访问页面时,它会破坏格式。
main.html
<!DOCTYPE html>
<html>
<head>
<script src="jquery-3.3.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://select2.github.io/select2-bootstrap-theme/css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://select2.github.io/select2-bootstrap-theme/css/select2-bootstrap.css">
<script type="text/javascript">
$(document).ready(function() {
$("#multiple").select2({
maximumSelectionLength: 5,
placeholder: "Click to select GW IDs",
theme: "bootstrap"
});
})
</script>
</head>
<body style="background-color:lightgrey;">
<div class="container">
<form method="POST" action="" class="login100-form">
<h1 align="center" style="font-variant: small-caps">Bank Portal System</h1><br>
<div class="form-group">
<label for="multiple" class="control-label">GW ID(s)</label>
<select id="multiple" class="form-control select2-multiple" multiple>
<optgroup label="Category 1">
<option>Value 1</option>
</optgroup>
<optgroup label="Category 2">
<option>Value 1</option>
<option>Value 2</option>
<option>Value 3</option>
</optgroup>
</select>
</div>
<div class="form-group">
<label for="default" class="control-label">From Date</label>
<input id="default" type="text" class="form-control" placeholder="Placeholder text">
</div>
<div class="form-group">
<label for="default" class="control-label">To Date</label>
<input id="default" type="text" class="form-control" placeholder="Placeholder text">
</div>
</body>
</html>
应用程序.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('main.html')
if __name__ == '__main__':
app.run(debug=True)
解决方案
为什么会发生这种情况
组件无法正确呈现的主要原因是依赖项未加载或注入到 DOM 中。
如何解决问题
确保正确加载所有依赖项/实用程序,因为这些组件在它们各自的 .js 和 .css 文件的帮助下工作/运行。
你提到的代码中的问题,我发现 Jquery 没有正确加载。您可以使用 CDN 中的 Jquery 来解决它。
例子:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
如果要在本地提供 Jquery 文件,请确保指定的路径正确。
推荐阅读
- r - 在 R 中,如何根据包含我要匹配的值的相邻列中的间隔来查找一列中的值?
- java - 每个循环周期替换变量名
- javascript - 如何用pdf.js提取内部链接的目标元素?
- ruby-on-rails - Ruby on Rails 与 IBM_DB2 Gem
- solr - 在 SOLR facet.pivot 分组中获得意外输出
- oracle - 在 oracle 中创建视图时获取输入太长错误
- javascript - 链接到使用 Java API for KML 在 KML 的描述气球中调用 REST API?
- ios - 如何使用 Realm 存储字符串枚举
- powerbi - Power BI Embedded 报表选取器
- reactjs - 在 onWheel 事件中使用 event.preventDefault 时,如何规避 reactjs 中的“被动事件监听器”