forked from CalicoUFSC/flask-dojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
38 lines (31 loc) · 803 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
38
import flask
from flask import Flask
from collections import OrderedDict
app = Flask(__name__)
data = OrderedDict()
@app.route('/save', methods=['post',])
def save():
title = flask.request.values["title"]
content = flask.request.values["content"]
data[title] = content
return content
@app.route('/')
def index():
return flask.render_template('index.html', data=data)
@app.route('/fetchall')
def fetch():
return "\n".join(data.values())
@app.route('/fetch/<title>')
def fetch_single(title):
if title in data:
return data[title]
else:
return flask.abort(404)
@app.route('/clear')
def clear():
global data
data = OrderedDict()
return "", 200
if __name__ == '__main__':
# to make it work with pycharm debugging
app.run(debug=True)