-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportfolio.py
More file actions
60 lines (51 loc) · 1.76 KB
/
portfolio.py
File metadata and controls
60 lines (51 loc) · 1.76 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
53
54
55
56
57
58
59
60
from flask import Flask, render_template, request, redirect
import csv
# from pyexpat.errors import messages
app = Flask(__name__)
@app.route('/')
def my_home():
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('D:\\Pycharm\\PythonProject\\ZTMprojects\\project3\\database.txt', mode='a') as database:
email = data['email']
subject = data['subject']
message = data['message']
file = database.write(f'\n\nemail:{email}\nsubject:{subject}\nmessage:{message}')
def write_to_csv(data):
with open('D:\\Pycharm\\PythonProject\\ZTMprojects\\project3\\database.csv', mode='a') as database2:
email = data['email']
subject = data['subject']
message = data['message']
csv_writer = csv.writer(database2, delimiter=',', lineterminator='\n', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow([email,subject,message])
@app.route('/submit_form', methods=['POST', 'GET'])
def submit_form():
if request.method == 'POST':
try:
data = request.form.to_dict()
write_to_csv(data)
return redirect('/thankyou.html')
except:
return 'did not save to database'
else:
return 'something went wrong, try again'
# @app.route('/index.html')
# def my_index():
# return r.ender_template('index.html')
#
# @app.route('/works.html')
# def my_works():
# return render_template('works.html')
#
# @app.route('/about.html')
# def my_about():
# return render_template('about.html')
#
# @app.route('/contact.html')
# def my_contact():
# return render_template('contact.html')
if __name__ == '__main__':
app.run(debug=True)