[python]代码库
from flask import Flask, render_template, request
from wtforms import Form, StringField, validators
app = Flask(__name__)
class ContactForm(Form):
name = StringField("Name", [validators.DataRequired()])
email = StringField("Email", [validators.DataRequired(), validators.Email()])
message = StringField("Message", [validators.DataRequired()])
@app.route("/contact", methods=["GET", "POST"])
def contact():
form = ContactForm(request.form)
if request.method == "POST" and form.validate():
# process the form data
return "Thank you for your message, " + form.name.data + "!"
return render_template("contact.html", form=form)
if __name__ == "__main__":
app.run()