Save form submissions
This commit is contained in:
parent
7fbf3cb2bd
commit
3d2e637d57
|
@ -1 +1,2 @@
|
||||||
.idea
|
.idea
|
||||||
|
dll_data
|
||||||
|
|
20
main.py
20
main.py
|
@ -1,29 +1,43 @@
|
||||||
|
import os, json
|
||||||
|
|
||||||
from flask import Flask, flash, redirect, render_template, request, session, abort
|
from flask import Flask, flash, redirect, render_template, request, session, abort
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
PROJECT_PATH = os.path.dirname(__file__)
|
||||||
|
DATA_DIR = os.path.join(PROJECT_PATH, "dll_data")
|
||||||
|
|
||||||
|
if not os.path.exists(DATA_DIR):
|
||||||
|
os.mkdir(DATA_DIR)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return "Index!"
|
return "Index!"
|
||||||
|
|
||||||
|
|
||||||
@app.route("/hello")
|
@app.route("/hello")
|
||||||
def hello():
|
def hello():
|
||||||
return "Hello World!"
|
return "Hello World!"
|
||||||
|
|
||||||
|
|
||||||
@app.route("/form")
|
@app.route("/form")
|
||||||
def form():
|
def form():
|
||||||
return render_template(
|
return render_template(
|
||||||
'form.html',**locals())
|
'form.html',**locals())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/form_post', methods = ['POST'])
|
@app.route('/form_post', methods = ['POST'])
|
||||||
def form_post():
|
def form_post():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
data = request.form
|
data = request.form
|
||||||
print("data: {}".format(data))
|
print("data: {}".format(data))
|
||||||
# TODO: save this data to a csv
|
filename = data['fname'] + "-" + data['lname']
|
||||||
# deploy this python app to server somewhere
|
file_path = os.path.join(DATA_DIR, filename)
|
||||||
# with a particular domain
|
with open(file_path, 'w') as f:
|
||||||
|
f.write(json.dumps(data))
|
||||||
return "form submitted"
|
return "form submitted"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run()
|
Loading…
Reference in New Issue