Javascript 循环以显示html卡中的所有信息
我正在尝试做一个烧瓶网站,将显示一个基于结果的特定数量的信息。 我已经设法从数据库中获取数据,我知道如何在一张html卡上显示数据,但我找不到一种基于我传递的数组长度显示所有信息的方法。 这是迄今为止的结果[网站][1] [1]: https://i.stack.imgur.com/ycqwt.pngJavascript 循环以显示html卡中的所有信息,javascript,python,html,flask,Javascript,Python,Html,Flask,我正在尝试做一个烧瓶网站,将显示一个基于结果的特定数量的信息。 我已经设法从数据库中获取数据,我知道如何在一张html卡上显示数据,但我找不到一种基于我传递的数组长度显示所有信息的方法。 这是迄今为止的结果[网站][1] [1]: https://i.stack.imgur.com/ycqwt.png {% extends "base.html" %} {% block title %} Search {% endblock %} {% block style %}{% en
{% 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 %}
您正在发送的数据以数组的形式
text1
。因此,您不必每次都重新渲染同一个模板,只需在其中循环并相应地设置值
例如,它应该如下所示:
{% for text in text1 %}
<h4><b>Name: {{ text[0] }}</b></h4>
<p>Country: {{ text[1]}}</p>
<p>Major: {{ text[2] }}</p>
{% endfor %}
希望这对你有用。如果您还有任何疑问,请告诉我。没问题,很高兴我能帮忙:)
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')
{% for text in text1 %}
<h4><b>Name: {{ text[0] }}</b></h4>
<p>Country: {{ text[1]}}</p>
<p>Major: {{ text[2] }}</p>
{% endfor %}
<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">
{% for text in text1 %}
<h4><b>Name: {{ text[0] }}</b></h4>
<p>Country: {{ text[1]}}</p>
<p>Major: {{ text[2] }}</p>
{% endfor %}
</div>