-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
62 lines (46 loc) · 1.7 KB
/
Copy pathapp.py
File metadata and controls
62 lines (46 loc) · 1.7 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
61
62
from flask import Flask, render_template, request
from forms import ContactForm
import get_yt__playlist_data
import os
from flask_mail import Message, Mail
app = Flask(__name__)
app.jinja_env.filters['zip'] = zip
SECRET_KEY = os.urandom(32)
app.config['SECRET_KEY'] = SECRET_KEY
@app.route('/')
def index():
return render_template('index.html')
@app.route('/videos')
def video():
return render_template(
'videos.html',
playlist_data=get_yt__playlist_data.yt_playlist_data,
playlist_ids=get_yt__playlist_data.yt_playlist_ids,
playlist_length=get_yt__playlist_data.amount_of_playlists
)
@app.route('/contactus', methods=["GET", "POST"])
def get_contact():
form = ContactForm()
if request.method == 'POST':
name = request.form["name"]
email = request.form["email"]
subject = request.form["subject"]
message = request.form["message"]
send_email(name, email, subject, message)
return render_template('email_success.html')
else:
return render_template('contact.html', form=form)
def send_email(name, email, subject, message):
app.config['MAIL_SERVER'] = 'smtp.googlemail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME')
app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD')
mail = Mail(app)
msg = Message(('You have a message from ' + name + " Subject: " + subject), sender='[email protected]',
recipients=['[email protected]'])
msg.body = ('Message From ' + email + '\n' + message)
with app.app_context():
mail.send(msg)
if __name__ == '__main__':
app.run()