-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (21 loc) · 719 Bytes
/
Copy pathapp.py
File metadata and controls
30 lines (21 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Flask: Form handling
"""
from flask import Flask, url_for, redirect, request
app = Flask(__name__)
HTML_FRAME_TOP = "<!DOCTYPE HTML>\n<html>\n<head>\n<title>Flask form example</title>\n</head>\n<body>\n"
HTML_FRAME_BOTTOM = "</body>\n</html>\n"
@app.route("/")
def index():
# redirect to form
return redirect(url_for("static", filename="form.html"))
@app.route("/sendform", methods=["POST"])
def sendform():
html = HTML_FRAME_TOP.replace("{css}", url_for("static", filename="style.css"))
html += "Name: " + request.form["name"] \
+ "<br />" \
+ "Email: " + request.form["email"]
html += HTML_FRAME_BOTTOM
return html
if __name__ == "__main__":
app.run()