-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.py
48 lines (36 loc) · 1.25 KB
/
routes.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
# All Imports
from flask import Flask, render_template, request, flash, url_for, redirect
from forms import ContactForm
from flask_mail import Message, Mail
app = Flask(__name__)
# configurations
app.config['SECRET_KEY'] = 'thisismysecret'
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = 'your app specific password'
mail = Mail(app)
@app.route('/index')
def index():
return render_template('index.html', title='Flask Index', success=True)
@app.route('/form', methods=['GET', 'POST'])
def contactForm():
form = ContactForm()
if request.method == 'GET':
return render_template('contact.html', form=form)
elif request.method == 'POST':
if form.validate() == False:
flash('All fields are required !')
return render_template('contact.html', form=form)
else:
msg = Message(form.subject.data, sender='[SENDER EMAIL]', recipients=['your reciepients gmail id'])
msg.body = """
from: %s <%s>
%s
"""% (form.name.data, form.email.data, form.message.data)
mail.send(msg)
return redirect(url_for('index'))
return '<h1>Form submitted!</h1>'
if __name__ == '__main__':
app.run(debug=True)