-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
42 lines (32 loc) · 1.13 KB
/
server.py
File metadata and controls
42 lines (32 loc) · 1.13 KB
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
import csv
from flask import Flask,redirect, render_template, request
app = Flask(__name__) #
@app.route('/')
def main():
return render_template('index.html')
@app.route('/<string:page_name>')
def html_page(page_name):
return render_template(page_name)
def write_to_file(data):
with open('database.txt', mode='a') as database:
email = data["email"]
subject = data["subject"]
message = data["message"]
data_to_file = database.write(f'\n{email},{subject},{message}')
def write_to_csv(data):
with open('database.csv', 'a', newline='') as database2:
email = data["email"]
subject = data["subject"]
message = data["message"]
csv_writer = csv.writer(database2, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
#csv_writer.writeheader
csv_writer.writerow([email,subject,message])
@app.route('/submit_form', methods=['POST', 'GET'])
def submit_form():
if request.method == 'POST':
data = request.form.to_dict()
print(data)
write_to_csv(data)
return redirect('/thankyou.html')
else:
return 'error! '