-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (36 loc) · 1.3 KB
/
app.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
from flask import Flask, jsonify, render_template, request, url_for
from mailer import Mailer
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
app = Flask(__name__)
limiter = Limiter(app, key_func=get_remote_address)
@app.route('/')
@app.route('/index')
def index(): # put application's code here
return render_template("index.html")
@app.route('/about')
def about(): # put application's code here
return render_template("about.html")
@app.route('/catalog')
def catalog(): # put application's code here
return render_template("catalog.html")
@app.route('/contacts')
def contacts(): # put application's code here
return render_template("contacts.html")
@app.route('/sign_up')
def sign_up(): # put application's code here
return render_template("sign_up.html")
@app.route('/mail', methods=['GET', 'POST'])
@limiter.limit("5/minute") #ratelimit
def mail():
if request.method == 'GET':
message = {'greeting': 'Hello from Flask!'}
return jsonify(message)
if request.method == 'POST':
mailer = Mailer(request.get_json())
return jsonify(mailer.send_email()), 200
@app.errorhandler(429)
def ratelimit_handler(err):
return jsonify("You have exceeded your rate-limit"), 429
if __name__ == '__main__':
app.run(debug=False)