-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpf_server.py
45 lines (32 loc) · 1.04 KB
/
pf_server.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Flask, render_template, url_for, request, redirect
import csv
app = Flask(__name__)
@app.route('/')
def home_page():
return render_template("index.html")
@app.route('/<string:page_name>')
def html_page(page_name):
return render_template(page_name)
def write_to_DB(data):
name = data['name']
email = data['email']
message = data['message']
with open('pf_Database.txt', mode='a') as db:
db.write(f'{name} said: \n{message} \nReply to them at {email}\n\n')
def write_to_CSV(data):
name = data['name']
email = data['email']
message = data['message']
with open('pf_Database.csv', mode='a', newline='') as db2:
csv_writer = csv.writer(db2, delimiter='|', quotechar='|')
csv_writer.writerow([name, email, message])
@app.route('/submit_form', methods=['POST', 'GET'])
def submit_form():
if request.method == 'POST':
data = request.form.to_dict()
write_to_CSV(data)
return redirect("/thankyou.html")
else:
return "Sorry! Something went wrong! Please try again."
if (__name__ == "__main__"):
app.run(debug=True)