1 Star 0 Fork 1

单敬博/SAMDrawer

forked from officeyutong/SAMDrawer 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
officeyutong 提交于 2019-05-05 17:11 . 支持了GET
from flask import Flask, render_template, request, make_response
from json import JSONEncoder
from io import BytesIO
import ds_drawer
import mimetypes
app = Flask("SAMDrawer")
@app.context_processor
def consts():
return {
"USING_SSL": False
}
@app.route("/", methods=["GET"])
def root():
return render_template("main.html")
@app.route("/draw", methods=["POST", "GET"])
def draw():
datas = None
if request.method == "GET":
datas = request.args
else:
datas = request.form
if "string" not in datas:
return encode_json({
"code": -1,
"message": "Please give a string."
})
string = datas["string"]
if len(string) > 50:
return encode_json({
"code": -1,
"message": "Too long.."
})
svg_data = ""
target = ds_drawer.generate_graph(string, "svg")
with open(target, "r") as file:
svg_data = file.read()
return encode_json({
"code": 0,
"data": svg_data
})
def encode_json(obj):
return JSONEncoder().encode(obj)
if __name__ == "__main__":
app.run(host="127.0.0.1", port="90")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/shanjb0221/SAMDrawer.git
[email protected]:shanjb0221/SAMDrawer.git
shanjb0221
SAMDrawer
SAMDrawer
master

搜索帮助