- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
Latest commit
29 lines (26 loc) · 953 Bytes
/
Copy pathserver.py
File metadata and controls
29 lines (26 loc) · 953 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
fromasyncoreimportwrite
fromflaskimportFlask, render_template, request, url_for, redirect
importcsv
app=Flask(__name__)
# print(__name__)
@app.route("/<string:page_name>")
defpage(page_name=None):
returnrender_template(page_name)
@app.route('/submit_form', methods=['GET', 'POST'])
defsubmit_form():
ifrequest.method=='POST':
try:
data=request.form.to_dict()
write_to_csv(data)
returnredirect('/thankyou.html')
except:
return'note save to db'
else:
return'something when wrong'
defwrite_to_csv(data):
withopen('database.csv', mode='a', newline='') asdatabase2:
email=data["email"]
subject=data["subject"]
message=data["message"]
csv_writer=csv.writer(database2, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow([email,subject,message])