【发布时间】:2017-01-17 00:36:18
【问题描述】:
我需要一些有关 MongoAlchemy 的帮助。我正在尝试使用 python、flask、Mongo DM 和 Mongo Alchemy(作为对象文档映射器)创建一个 Web 应用程序,并且我正在努力更新现有文档。
我的问题是我无法通过它的对象 ID 更新现有文档。下面我附上我的 def 以供更新
@app.route('/update', methods =[ 'GET', 'POST' ])
def update():
if request.method == 'POST':
id = request.form['object_id'] # Getting values with html
patientzero = BloodDoonor.query.get_or_404(id)
first_name = request.form['name']# Getting values with htmlform
last_name = request.form['surname']# Getting values with html form
blood_type = request.form['blood_type']# Getting values with html
update_record = BloodDoonor.patientzero.update(BloodDoonor.last_name = last_name)
return render_template('update.html', result = result)
Flask 给了我这个错误:
AttributeError AttributeError: 类型 对象“BloodDoonor”没有属性“patientzero”
我对 Python 很陌生,而且代码不是很好。请原谅我上面给出的草率描述。任何帮助将不胜感激。
【问题讨论】:
-
试试
update_record = patientzero.update(BloodDoonor.last_name = last_name)
标签: flask mongoalchemy