12 Star 42 Fork 9

莽就对了/sorrypy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
app.py 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
莽就对了 提交于 2023-07-26 11:12 . + apimake
#!/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)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/east196/sorrypy.git
git@gitee.com:east196/sorrypy.git
east196
sorrypy
sorrypy
master

搜索帮助