如何将照片上传到数据库,然后在div中显示该照片python,flask和mongodb

问题描述

正如标题所述,我已经使用Bootstrap库实现了“上传照片”功能。 我想做的是存储用户上传的照片,然后使用for循环浏览上传的照片以显示在我的轮播中。

到目前为止,我已经有了以下代码来存储上传的图像:

@app.route('/insert_recipe',methods =['POST'])
def insert_recipe():
    mongo.db.recipes.insert_one(request.form.to_dict())
    if 'recipe_image' in request.files:
        recipe_image = request.file['recipe_image']
        mongo.save_file(recipe_image.filename,recipe_image)
        mongo.db.recipes.insert_one({'recipe_image_name':recipe_image})
    return redirect(url_for('get_recipes'))

目前,所有要做的就是将照片的文件名存储在已上传的MongoDB中。我已经从Google搜索中尝试了不同的方法,但没有一个起作用。

希望有人可以帮助我。

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)