python - Jinja2/Flask,我无法从复选框中获取动态值
问题描述
所以我有这个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()
管理视图.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"
将其发送到数据库,问题是当我运行代码时,没有"confidencial"
inproyect.py
和adminvie.py
,它运行并在数据库中进行更改,但是当我再次尝试使用"confidencial"
, 并进行更改checkbox
,如果复选框被选中并且我未选中它,则值为无,但如果我将其选中,则默认值为一个,控制台说该值为空,,MySQLdb._exceptions.OperationalError: (1048, "Column 'EMPRESA_CONFIDENCIAL' cannot be null")
该过程没有得到值"1"
或"0"
来自checkbox
修改后的值,但我得到的其他值如 id 和 estado 确实,我认为是if
语句,我如何使用语句从checkbox
html 中获取值if
解决方案
我认为您应该将选中的复选框添加到两个复选框中。
推荐阅读
- r - Visualizing All Possible Linear Regression Predictions from all Combinations of Regression Variables
- node.js - Is there a way to do multiple efficient (index-using) finds in one request?
- celery - 在 celery 中,当任务入队时,将上下文元数据从发送方进程传递给工作人员的适当方法是什么?
- reactjs - React Router Dom hangs browser
- php - UPDATE query on php laravel not working, fetchAll()
- html - SVG 图像标签中的图像显示在桌面浏览器中,而不是 iphone
- python - Python链表无法保存头节点
- android - Android Visualizer FFT 数据取决于体积
- python - Pandas:如果多个列中的一个以上为零,则删除行
- react-native - 如何将应用程序的当前主题传递给 StyleSheet.create()?