-
Notifications
You must be signed in to change notification settings - Fork 113
/
app.py
48 lines (34 loc) · 1.18 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
48
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from flask import Flask
from flask import redirect, render_template, request
app = Flask(__name__)
@app.route('/')
def hello():
return redirect('/tpl/sorry/')
@app.route('/tpl/<name>/')
def tpl(name="sorry"):
app.logger.debug(name)
return render_template('{name}/index.html'.format(name=name))
@app.route('/tpl/<name>/make', methods=['POST', 'GET'])
def tplmake(name="sorry"):
if request.method == 'POST':
a = request.get_data()
idx_sentence = json.loads(a)
sentences = list(idx_sentence.keys())
for idx, sentence in idx_sentence.items():
sentences[int(idx)] = sentence
app.logger.debug(json.dumps(sentences, ensure_ascii=False))
import render
path = render.render_gif(name, sentences)
app.logger.debug(path)
return '<p><a href="/{path}" target="_blank"><p>点击下载</p></a></p>'.format(path=path)
else:
return '<h1>只接受post请求!</h1>'
@app.errorhandler(404)
def not_found(error):
return render_template('404.html'), 404
if __name__ == '__main__':
app.debug = True
app.run(host="0.0.0.0", port=5997)