flask_server.py 1.18 KB
Newer Older
Mindiell's avatar
Mindiell committed
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
#encoding: utf-8
from flask import Flask, render_template, redirect, request, url_for

from vlozit import Vlozit

app = Flask(__name__)
app.config.from_object('config')
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.jinja_env.lstrip_blocks = True

# ================================================
# Main
# ================================================
@app.route('/')
def index():
    return render_template('index.html')

@app.route('/about')
def about():
    return render_template('about.html')

@app.route('/send', methods=['POST'])
def send():
    """
    Sending a paste via the web interface
    """
    return redirect(Vlozit().create_paste(request.form['paste']))

@app.route('/p')
def paste():
Mindiell's avatar
Mindiell committed
32
    # Get first and only key arg to use as paste identifier
Mindiell's avatar
Mindiell committed
33
    for key in request.args.keys():
Mindiell's avatar
Mindiell committed
34
35
36
37
        template = Vlozit().get_template(key)
        if template is not None:
            return render_template()
    return redirect('/')
Mindiell's avatar
Mindiell committed
38
39
40
41
42
43
44


# ================================================
# Launching
# ================================================
if __name__ == '__main__':
    app.run(debug=app.config['DEBUG'], host=app.config['HOST'], port=app.config['FLASK_PORT'])