【发布时间】:2020-05-25 02:30:33
【问题描述】:
所以我有这个html
<label class="continer">Empresa Confidencial
{% if proyecto.10 == 1 %}
<input type="checkbox" id="confidencial" name="confidencial" value="1" checked>
{% else %}
<input type="checkbox" id="confidencial" name="confidencial" value="0">
{% endif %}
<span class="checkmark"></span>
</label>
项目.py
def editar_(confidencial,estado,id):
cur = mysql.connection.cursor()
cur.execute('UPDATE proyecto set EMPRESA_CONFIDENCIAL=%s,estado=%s where PK_PROYECTO=%s', (confidencial,estado, id,))
mysql.connection.commit()
adminviews.py
@app.route("/editar", methods=["POST"])
def editar():
print('.................................................................................')
id = request.form['id']
estado = request.form.get('estado')
confidencial = request.form.get('confidencial')
print(id,str(estado), str(confidencial))
pr.editar_(confidencial,estado,id)
return redirect(url_for('empresasT'))
我需要获取值"1" 或"0" 将其发送到数据库,问题是当我运行代码时,在proyect.py 和adminvie.py 中没有"confidencial",它运行并在数据库中进行更改,但是当我再次尝试使用"confidencial" 并在checkbox 中进行更改时,如果选中该复选框并且我未选中它,则值为无,但如果我将其选中,则value 是默认值,控制台说该值为null,MySQLdb._exceptions.OperationalError: (1048, "Column 'EMPRESA_CONFIDENCIAL' cannot be null"),该进程在修改后没有从checkbox 获取值"1" 或"0",而是我的其他值像 id 和 estado 一样,我认为是 if 语句,我如何使用 if 语句从 html 中的 checkbox 获取值
【问题讨论】: