我正在尝试做一个烧瓶网站,将显示一个基于结果的特定数量的信息。 我已经设法从数据库中获取数据,我知道如何在一张html卡上显示数据,但我找不到一种基于我传递的数组长度显示所有信息的方法。 这是迄今为止的结果[网站][1] [1]: https://i.stack.imgur.com/ycqwt.png
{% extends "base.html" %}
{% block title %} Search {% endblock %}
{% block style %}{% endblock %}
{% block body %}
<h1 align="center">Resluts</h1>
<div class="card" id = "element1">
<img src={{url_for('static', filename='pictures/uni.jpg')}} alt="Avatar" style="width:20%">
<div class="container">
<h4><b>Name: {{ name }}</b></h4>
<p>Country: {{ country }}</p>
<p>Major: {{ major }}</p>
<p>Slect and visit: {{ link }}</p>
</div>
<div class="card">
<img src={{url_for('static', filename='pictures/uni.jpg')}} alt="Avatar" style="width:20%">
<div class="container">
<h4><b>Name: {{ name }}</b></h4>
<p>Country: {{ country }}</p>
<p>Major: {{ major }}</p>
<p>Slect and visit: {{ link }}</p>
</div>
<p>Here is my variable: {{ text1 }}</p>
{% endblock %}
我也试过了
<!DOCTYPE html>
<html>
<body>
<div class="card" id = "div1">
<img src={{url_for('static', filename='pictures/uni.jpg')}} alt="Avatar" style="width:20%">
<div class="container">
<h4><b>Name: {{ name }}</b></h4>
<p>Country: {{ country }}</p>
<p>Major: {{ major }}</p>
<p>Slect and visit: {{ link }}</p>
</div>
<button onclick="body()">Try it</button>
<script>
var body = document.getElementsByTagName('body')[2],
newdiv = document.createElement('container');
//add an id
body.appendChild(newdiv);
}
</script>
</body>
</html>
我想传递一系列的结果和长度,以及由此产生的魔力 这是app.py中的@app.route(“/search”,methods=[“POST”,“GET”])
if request.method == "POST":
major = request.form["major"]
country = request.form["country"]
price = request.form["price"]
global universities
universities = search_universities(country, major, price)
print(universities)
if universities != []:
#for x in universities:
# name = x[0]
# country = x[1]
# major = x[2]
# price = x[3]
# link = x[4]
list_length = len(universities)
return render_template('result.html', text1 = universities, list_length = list_length)
else:
return render_template('result.html')
return render_template('search.html')
您正在发送的数据是数组
text1
的形式。因此,您不必每次都重新渲染同一个模板,只需在其中循环并相应地设置值例如,它应该如下所示:
将此项用作参考(
text1
是正在传递的数据):希望这对你有用。如果你还有任何疑问,请告诉我
相关问题 更多 >
编程相关推荐