代码拉取完成,页面将自动刷新
#!/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.route('/api/<name>/make', methods=['POST', 'GET'])
def apimake(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 f"/{path}"
else:
return '只接受post请求!'
@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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。