-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
72 lines (60 loc) · 1.96 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from flask import Flask,render_template,request,redirect
import csv
app = Flask(__name__)
print(__name__)
@app.route('/')
def my_home():
# return 'Hello, Sany!'
return render_template('index.html')
@app.route('/<username>/<int:post_id>')
def good_morning(username=None,post_id=None):
# return 'Hello, Sany!'
return render_template('index.html',name=username,post_id=post_id)
@app.route('/<string:page_name>')
def html_page(page_name:None):
# return 'Hello, Sany!'
return render_template(page_name)
@app.route('/submit_form', methods=['POST', 'GET'])
def submit_form():
if request.method == 'POST':
try:
data = request.form.to_dict()
# with open('database.txt',mode='a') as db_file:
# db_file.write(str(data))
# print(data)
write_to_csv(data)
return redirect('thank_you.html')
except:
return "Sorry! Could not save the data!"
else:
return "Something went wrong"
def write_to_csv(data):
with open('database.csv',mode='a') as database:
email = data['email']
subject = data['subject']
message = data['message']
csv_writer = csv.writer(database, delimiter=',',quotechar='"',quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow([email,subject,message])
# @app.route('/index.html')
# def index():
# # return 'Hello, Sany!'
# return render_template('index.html')
# @app.route('/about.html')
# def about():
# # return 'Hello, Sany!'
# return render_template('about.html')
# @app.route('/components.html')
# def components():
# # return 'Hello, Sany!'
# return render_template('components.html')
# @app.route('/contact.html')
# def contact():
# # return 'Hello, Sany!'
# return render_template('contact.html')
# @app.route('/works.html')
# def works():
# # return 'Hello, Sany!'
# return render_template('works.html')
# @app.route('/blog')
# def blog():
# return 'Hello, In the BLOG!'