【发布时间】:2020-08-21 18:17:04
【问题描述】:
在学校项目中使用 Flask pymongo,这是一个分享食谱的网站。 我想返回我在主页上使用的字典,以便网站知道单击时它应该显示什么食谱。但是,在终端中它似乎返回(我想要的方式)作为字典但是当它实际返回一个字典的字符串,所以我不能使用它。
来自 App.py:
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'GET' or request.form.get('search') == '':
recipes = mongo.db.recipe.find()
return render_template('home.html', recipes=recipes)
从主页:循环遍历 mongodb 中的食谱,以便我可以获取 recipe.recipe_name 等值。
{% for recipe in recipes %}
<a href="{{url_for('view_recipe', recipe=recipe)}}"
我将变量返回错误吗?还有另一种方法吗? 非常感谢所有帮助!
【问题讨论】:
标签: python mongodb flask pymongo