Compare commits

...

2 Commits

Author SHA1 Message Date
notplants b3e757af88 Copywriting 2022-03-15 18:41:13 -06:00
notplants 3d2e637d57 Save form submissions 2022-03-15 18:40:08 -06:00
2 changed files with 21 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.idea
dll_data

26
main.py
View File

@ -1,29 +1,43 @@
import os, json
from flask import Flask, flash, redirect, render_template, request, session, abort
app = Flask(__name__)
@app.route("/")
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("/index")
def index():
return "Index!"
@app.route("/hello")
def hello():
return "Hello World!"
@app.route("/form")
@app.route("/")
def form():
return render_template(
'form.html',**locals())
@app.route('/form_post', methods = ['POST'])
def form_post():
if request.method == 'POST':
data = request.form
print("data: {}".format(data))
# TODO: save this data to a csv
# deploy this python app to server somewhere
# with a particular domain
return "form submitted"
filename = data['fname'] + "-" + data['lname']
file_path = os.path.join(DATA_DIR, filename)
with open(file_path, 'w') as f:
f.write(json.dumps(data))
return "your form submission was saved, thank you"
if __name__ == "__main__":
app.run()