-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
52 lines (33 loc) · 1.13 KB
/
server.py
File metadata and controls
52 lines (33 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
42
43
44
45
46
47
48
49
50
51
52
from flask import Flask, render_template, request, redirect
import csv
app = Flask(__name__)
print(app)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/<string:page_name>')
def project(page_name):
return render_template(page_name)
def write_to_csv(data):
with open('database.csv', mode='a', newline='') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=['email','full_name','subject','message'])
writer.writerow(data)
def write_to_database(data):
f = open("database.txt", mode="a")
f.write(f'''
email : {data.get('email')}
Full Name : {data.get('full_name')}
Subject : {data.get('subject')}
Message : {data.get('message')}
================================================================''')
f.close()
@app.route('/submit_form', methods=['POST', 'GET'])
def submit_form():
if request.method == 'POST':
data = request.form.to_dict()
write_to_database(data)
print(data)
write_to_csv(data)
return redirect('Thanku.html')
else:
return 'somethings wrong'