-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
37 lines (26 loc) · 772 Bytes
/
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
from flask import Flask, redirect, abort, render_template, request
import db
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/<shortcode>')
def get(shortcode):
link = db.read(shortcode)
if link is None:
abort(404)
else:
db.update(shortcode, 'register_click')
return redirect(link)
@app.route('/create', methods=['POST'])
def new():
if request.method == 'POST':
link = request.form['link']
shortcode = db.create(link)
return render_template('link-created.html', link=link, shortcode=shortcode)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
if __name__ == '__main__':
db.init_db()
app.run()