尝试将值从Flask模板返回到使用MongoDB作为数据库的Python中
我想把一些数据输入一个烧瓶应用程序。请记住我在这方面是新手。我正在尝试做一行选择。我使用下拉框,也使用引导 在我的Flask应用程序(index.py)中,我得到了一些值。我在MongoDB中的收藏:尝试将值从Flask模板返回到使用MongoDB作为数据库的Python中,python,mongodb,twitter-bootstrap,flask,Python,Mongodb,Twitter Bootstrap,Flask,我想把一些数据输入一个烧瓶应用程序。请记住我在这方面是新手。我正在尝试做一行选择。我使用下拉框,也使用引导 在我的Flask应用程序(index.py)中,我得到了一些值。我在MongoDB中的收藏: coll = db.collection_names() try: return flask.render_template('pricHistory.html', title=title, pageType=pageType, coll=coll) except Exception a
coll = db.collection_names()
try:
return flask.render_template('pricHistory.html', title=title, pageType=pageType, coll=coll)
except Exception as e:
return str("Exception is been handled at Price-History: ", e)
在网页上,我使用了如下内容:
收藏
{coll%中的i的%1}
{%if i==“system.index”%}
{%else%}
{%endif%}
{%endfor%}
如何捕获所选值并在index.py中再次使用它以获得第二个下拉列表。因为通过选择第一个下拉列表(集合),第二个下拉列表应该在mongoDB中包含文档
第二个是类似的。我的例子是:
中央处理器
{cpu%中的i的%1}
{%endfor%}
您有HTML方面的经验吗?如果您正在执行get请求以提取数据,则需要使用()然后在烧瓶端使用request.args.get()。另外,为什么在渲染模板时要尝试除块之外的其他方法?谢谢大家!我将尝试使用get&post方法来完成它
<div class="btn-group first">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Collections <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" onclick>
{% for i in coll %}
{% if i == "system.indexes" %}
{% else %}
<li class="test"><a href="#">{{ i }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
<div class="btn-group second">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
CPU <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" onclick>
{% for i in cpu %}
<li class="test"><a href="#">{{ i }}</a></li>
{% endfor %}
</ul>
</div>