-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (33 loc) · 1.21 KB
/
Copy pathapp.py
File metadata and controls
45 lines (33 loc) · 1.21 KB
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
from flask import Flask, render_template, redirect, url_for, make_response, request, flash
import json
from options import DEFAULTS
app = Flask(__name__)
app.secret_key = 'dfkf[]dperv@cdhwshdöüó355cdédp&réfrofhwshdö32mlw2'
@app.route('/')
def index():
return render_template('index.html', data=get_saved_data())
def get_saved_data():
try:
data = json.loads(request.cookies.get('character'))
except TypeError:
data = {}
return data
@app.route('/save', methods=['POST'])
def save_form():
flash("Changes saved!")
data = get_saved_data()
print(data)
print(request.form.items())
data.update(dict(request.form.items()))
print(data)
# we need to use this because of the cookies
# otherwise return redirect would be enough
response = make_response(redirect(url_for('builder')))
# response = make_response(render_template('builder.html', data=get_saved_data(), options=DEFAULTS))
response.set_cookie('character', json.dumps(data))
return response
@app.route('/builder')
def builder():
return render_template('builder.html', data=get_saved_data(), options=DEFAULTS)
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=80)