cs
作者:互联网
lib代码:
from wtforms import Form,StringField,IntegerField,SubmitField from wtforms.validators import DataRequired,NumberRange class AddForm(Form): iFirst=IntegerField('First',validators=[DataRequired(),NumberRange(min=1,max=10000,message="该值取值区间在1-10000")]) iSecond=IntegerField('Second',validators=[DataRequired(),NumberRange(min=1,max=10000,message="该值取值区间在1-10000")]) iSum=IntegerField('Sum') submit=SubmitField("提交")
main代码:
from Lib import gcodeform from wtforms import Form,IntegerField,SubmitField from wtforms.validators import DataRequired,Length from flask import Flask, render_template, request,url_for,flash app = Flask(__name__) app.secret_key="12345" @app.route('/') @app.route('/Index',methods = ['POST','GET']) def Index(): if request.method=='GET': f1=gcodeform.AddForm() iSum=11 return render_template('IndexC.html',form=f1,iSum=iSum) else: f2=gcodeform.AddForm(request.form) if f2.validate(): iFirst=f2.iFirst.data iSecond=f2.iSecond.data iSum=iSecond+iFirst f2.iSum=iSum return render_template('IndexC.html',form=f2) else: flash("请输入整数数值,范围在1-10000之间.") return "err" if __name__ == '__main__': app.run(debug = False,port=6669)
html:
<!DOCTYPE html> <html> <head> <title>质数展示</title> </head> <body> <h2>质数展示</h2> <form action="/Index" method="POST"> {{form.csrf_token}} {{form.iFirst.label}}{{form.iFirst}}+{{form.iSecond.label}}{{form.iSecond}}={{form.iSum.label}}{{form.iSum}}<br> {{form.submit}}<br> </form> {% for message in get_flashed_messages() %} {{ message }} {% endfor %} </body> </html>
标签:__,f2,form,iSecond,iSum,iFirst,cs 来源: https://www.cnblogs.com/exesoft/p/16333050.html