-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
47 lines (38 loc) · 1.13 KB
/
server.py
File metadata and controls
47 lines (38 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
from flask import Flask,url_for,request, redirect
from flask import render_template as rt
import csv
app = Flask(__name__)
@app.route('/')
def home():
return rt('index.html')
@app.route('/works')
def works():
return rt('works.html')
@app.route('/about')
def about():
return rt('about.html')
@app.route('/contact')
def contact():
return rt('contact.html')
def write_file(data):
with open('database.txt', mode='a') as database:
email=data['email']
subject=data['subject']
message=data['message']
file=database.write(f'{email},{subject},{message}\n')
def write_file_csv(data):
with open('databasee.csv', mode='a') as database_csv:
email1=data['email']
subject1=data['subject']
message1=data['message']
file_csv=csv.writer(database_csv,delimiter=',',quotechar='"',quoting=csv.QUOTE_MINIMAL)
file_csv.writerow([email1,subject1,message1])
@app.route('/submit_f', methods=['POST', 'GET'])
def submit_f():
if request.method == "POST":
data=request.form.to_dict()
write_file(data)
write_file_csv(data)
return rt('submit_f.html')
else:
return 'something went wrong please try again'