python - HTML Python/Flask 传递值 (int)
问题描述
sum_test.py
def sum_t(a, b):
return a+b
主文件
@app.route('/test', methods=["GET", "POST"])
def print_test():
if request.method == "POST":
# getting input with name = aa in HTML form
a = request.form.get("aa")
# getting input with name = bb in HTML form
b = request.form.get("bb")
result = sum_test.sum_t(a, b)
return str(result)
return render_template('test.html')
结果是
1 + 1 = 11
但我想要的结果
1 + 1 = 2
解决方案
这个答案应该是不言自明的:)
a = request.form.get("aa", type = int)
您需要将表单字段作为 int 值获取,以便将它们作为数学表达式进行操作。
推荐阅读
- java - 如何使用 Java 函数编写程序来确定用户输入的 4 个整数是形成正方形还是矩形?
- windows - 如何从 docker 中提取 selenium/hub?
- jenkins - groovy 模块可以访问基于 jenkinsfile 的部署管道中的全局变量,这样做是个好主意吗?
- javafx - 我可以对 JavaFX 工具提示的一部分进行样式化吗?
- python-3.x - Visual Studio 包 Python
- java - 如何在准备好的语句查询中使用 oracle SYSTIMESTAMP?
- python - 为什么python中socket的accept方法无法退出
- json - 如何使用 AWS 胶水获取存储在 s3 中的模式或已处理的嵌套 json 文件压缩(gzip)?
- node.js - 重置 Sequelize 数据库
- python - 我的神经网络模型准确率始终为 50%