小编这次要给大家分享的是详解Python中Flask框架如何实现简单加法工具,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。

主程序mainaddfunc.py
from flask import Flask, render_template, request, url_for
from add import *
app = Flask(__name__)
@app.route('/', methods=['GET'])
def home():
return render_template('index.html')
@app.route('/', methods=['POST'])
def add():
a = request.form['adder1']
b = request.form['adder2']
try:
a = float(a)
b = float(b)
result = sum_function(a, b)
return render_template('index.html', result=result, var1=a, var2=b)
except:
return render_template('index.html', message='inputs false!!!', var1=a, var2=b)
if __name__ == '__main__':
app.run(port=8080)