修改了返回静态文件方式, 修改前的状态码为302 修改后为200

This commit is contained in:
MarkusJoe
2022-02-11 16:26:11 +08:00
parent 34f8524606
commit 9176ddc25b
5 files changed
+216 -217

No files matched your search

+16 -17
View File
@@ -12,14 +12,13 @@ from flask import Flask
from flask import request
from flask import Response
from flask import make_response
from flask import send_from_directory
from flask import jsonify
from bin.core.error import ErrorProcess
from bin.core.render_ import render_temp_
from bin.core.b64img import re_sort_number_image
from bin.utils.error import ErrorProcess
from bin.utils.render_ import render_temp_
from bin.utils.b64img import re_sort_number_image
from db.db import fetch_data
app = Flask(__name__)
app = Flask(__name__, static_url_path='')
app.config['JSON_SORT_KEYS'] = False # 设置JSON消息不根据字母顺序重新排序
app.config['JSON_AS_ASCII'] = False # 设置JSON消息显示中文
@@ -31,7 +30,7 @@ def miss(reason) -> Response:
:param reason:
:return:
"""
return jsonify({'code': 404, 'msg': f'{reason}', 'data': []})
return jsonify({'code': 404, 'msg': f'{reason}', 'data': None})
@app.errorhandler(500)
@@ -41,16 +40,7 @@ def error(reason) -> Response:
:param reason:
:return:
"""
return jsonify({'code': 500, 'msg': f'{reason}', 'data': []})
@app.route('/favicon.ico', methods=['GET', 'POST'])
def favicon() -> Response:
"""
主页图标
:return:
"""
return app.send_static_file('favicon.ico')
return jsonify({'code': 500, 'msg': f'{reason}', 'data': None})
def build_page(name: str, length: int, theme: str) -> list[bool or Response] or list[bool or str] or bool:
@@ -111,13 +101,22 @@ def api_page() -> Response or str:
return ErrorProcess().arg_not_be_full()
@app.route('/favicon.ico', methods=['GET', 'POST'])
def favicon() -> Response:
"""
主页图标
:return:
"""
return app.send_static_file('favicon.ico')
@app.route('/', methods=['GET', 'POST'])
def index() -> Response:
"""
索引页面
:return:
"""
return send_from_directory('./static', 'index.html')
return app.send_static_file('index.html')
if __name__ == '__main__':
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/5
# @File Name: __init__.py.py
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/5
# @File Name: __init__.py.py
+70 -70
View File
@@ -1,70 +1,70 @@
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/3
# @File Name: b64img.py
import sqlite3
from typing import Any
from db.db import fetch_table
def re_sort_number_image(origin_number: str, theme: str) -> tuple[bool, bool, bool, bool] or list[
bool or list[Any] or Any]:
"""
返回一个排列好的svg base64代码列表
:param theme:
:param origin_number:
:return:
"""
table_list = fetch_table()
if theme not in table_list:
return False, False, False, False
width_list = []
height_list = []
b_64_list = []
cursor.execute('select * from %(name)s' % {'name': theme})
data = cursor.fetchall()
for i in data:
width_list.append(i[2])
height_list.append(i[3])
b_64_list.append(i[1])
final_b64_img_code = []
if origin_number != '0000000000':
for i in origin_number:
if i == '0':
final_b64_img_code.append(b_64_list[0])
elif i == '1':
final_b64_img_code.append(b_64_list[1])
elif i == '2':
final_b64_img_code.append(b_64_list[2])
elif i == '3':
final_b64_img_code.append(b_64_list[3])
elif i == '4':
final_b64_img_code.append(b_64_list[4])
elif i == '5':
final_b64_img_code.append(b_64_list[5])
elif i == '6':
final_b64_img_code.append(b_64_list[6])
elif i == '7':
final_b64_img_code.append(b_64_list[7])
elif i == '8':
final_b64_img_code.append(b_64_list[8])
elif i == '9':
final_b64_img_code.append(b_64_list[9])
return [True, final_b64_img_code, width_list[0], height_list[0]]
else:
for i in range(10):
final_b64_img_code.append(b_64_list[0])
return [True, final_b64_img_code, width_list[0], height_list[0]]
if __name__ != '__main__':
conn = sqlite3.connect('./bin/assets/theme.db', check_same_thread=False)
cursor = conn.cursor()
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/3
# @File Name: b64img.py
import sqlite3
from typing import Any
from db.db import fetch_table
def re_sort_number_image(origin_number: str, theme: str) -> tuple[bool, bool, bool, bool] or list[
bool or list[Any] or Any]:
"""
返回一个排列好的svg base64代码列表
:param theme:
:param origin_number:
:return:
"""
table_list = fetch_table()
if theme not in table_list:
return False, False, False, False
width_list = []
height_list = []
b_64_list = []
cursor.execute('select * from %(name)s' % {'name': theme})
data = cursor.fetchall()
for i in data:
width_list.append(i[2])
height_list.append(i[3])
b_64_list.append(i[1])
final_b64_img_code = []
if origin_number != '0000000000':
for i in origin_number:
if i == '0':
final_b64_img_code.append(b_64_list[0])
elif i == '1':
final_b64_img_code.append(b_64_list[1])
elif i == '2':
final_b64_img_code.append(b_64_list[2])
elif i == '3':
final_b64_img_code.append(b_64_list[3])
elif i == '4':
final_b64_img_code.append(b_64_list[4])
elif i == '5':
final_b64_img_code.append(b_64_list[5])
elif i == '6':
final_b64_img_code.append(b_64_list[6])
elif i == '7':
final_b64_img_code.append(b_64_list[7])
elif i == '8':
final_b64_img_code.append(b_64_list[8])
elif i == '9':
final_b64_img_code.append(b_64_list[9])
return [True, final_b64_img_code, width_list[0], height_list[0]]
else:
for i in range(10):
final_b64_img_code.append(b_64_list[0])
return [True, final_b64_img_code, width_list[0], height_list[0]]
if __name__ != '__main__':
conn = sqlite3.connect('./bin/assets/theme.db', check_same_thread=False)
cursor = conn.cursor()
File renamed without changes.
+123 -123
View File
@@ -1,123 +1,123 @@
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/5
# @File Name: render_.py
from flask import render_template
def render_temp_(length: int, name: str, image_list: list, width: int, height: int) -> str:
"""
代码很烂写到隐蔽的地方就看不见了
:param height:
:param width:
:param length:
:param name:
:param image_list:
:return:
"""
position_list = []
for i in range(0, length):
position_list.append(i * width)
file_name = f'index{length}.html'
# 自己写的都看不下去了
if length == 7:
return render_template(file_name,
title=name,
g_width=length * width,
width=width,
height=height,
x_position_0=position_list[0],
x_position_1=position_list[1],
x_position_2=position_list[2],
x_position_3=position_list[3],
x_position_4=position_list[4],
x_position_5=position_list[5],
x_position_6=position_list[6],
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
svg_img_2=f'{image_list[2]}',
svg_img_3=f'{image_list[3]}',
svg_img_4=f'{image_list[4]}',
svg_img_5=f'{image_list[5]}',
svg_img_6=f'{image_list[6]}'
)
elif length == 8:
return render_template(file_name,
title=name,
g_width=length * width,
width=width,
height=height,
x_position_0=position_list[0],
x_position_1=position_list[1],
x_position_2=position_list[2],
x_position_3=position_list[3],
x_position_4=position_list[4],
x_position_5=position_list[5],
x_position_6=position_list[6],
x_position_7=position_list[7],
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
svg_img_2=f'{image_list[2]}',
svg_img_3=f'{image_list[3]}',
svg_img_4=f'{image_list[4]}',
svg_img_5=f'{image_list[5]}',
svg_img_6=f'{image_list[6]}',
svg_img_7=f'{image_list[7]}'
)
elif length == 9:
return render_template(file_name,
title=name,
g_width=length * width,
width=width,
height=height,
x_position_0=position_list[0],
x_position_1=position_list[1],
x_position_2=position_list[2],
x_position_3=position_list[3],
x_position_4=position_list[4],
x_position_5=position_list[5],
x_position_6=position_list[6],
x_position_7=position_list[7],
x_position_8=position_list[8],
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
svg_img_2=f'{image_list[2]}',
svg_img_3=f'{image_list[3]}',
svg_img_4=f'{image_list[4]}',
svg_img_5=f'{image_list[5]}',
svg_img_6=f'{image_list[6]}',
svg_img_7=f'{image_list[7]}',
svg_img_8=f'{image_list[8]}',
)
elif length == 10:
return render_template(file_name,
title=name,
g_width=length * width,
width=width,
height=height,
x_position_0=position_list[0],
x_position_1=position_list[1],
x_position_2=position_list[2],
x_position_3=position_list[3],
x_position_4=position_list[4],
x_position_5=position_list[5],
x_position_6=position_list[6],
x_position_7=position_list[7],
x_position_8=position_list[8],
x_position_9=position_list[9],
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
svg_img_2=f'{image_list[2]}',
svg_img_3=f'{image_list[3]}',
svg_img_4=f'{image_list[4]}',
svg_img_5=f'{image_list[5]}',
svg_img_6=f'{image_list[6]}',
svg_img_7=f'{image_list[7]}',
svg_img_8=f'{image_list[8]}',
svg_img_9=f'{image_list[9]}'
)
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/5
# @File Name: render_.py
from flask import render_template
def render_temp_(length: int, name: str, image_list: list, width: int, height: int) -> str:
"""
代码很烂写到隐蔽的地方就看不见了
:param height:
:param width:
:param length:
:param name:
:param image_list:
:return:
"""
position_list = []
for i in range(0, length):
position_list.append(i * width)
file_name = f'index{length}.html'
# 自己写的都看不下去了
if length == 7:
return render_template(file_name,
title=name,
g_width=length * width,
width=width,
height=height,
x_position_0=position_list[0],
x_position_1=position_list[1],
x_position_2=position_list[2],
x_position_3=position_list[3],
x_position_4=position_list[4],
x_position_5=position_list[5],
x_position_6=position_list[6],
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
svg_img_2=f'{image_list[2]}',
svg_img_3=f'{image_list[3]}',
svg_img_4=f'{image_list[4]}',
svg_img_5=f'{image_list[5]}',
svg_img_6=f'{image_list[6]}'
)
elif length == 8:
return render_template(file_name,
title=name,
g_width=length * width,
width=width,
height=height,
x_position_0=position_list[0],
x_position_1=position_list[1],
x_position_2=position_list[2],
x_position_3=position_list[3],
x_position_4=position_list[4],
x_position_5=position_list[5],
x_position_6=position_list[6],
x_position_7=position_list[7],
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
svg_img_2=f'{image_list[2]}',
svg_img_3=f'{image_list[3]}',
svg_img_4=f'{image_list[4]}',
svg_img_5=f'{image_list[5]}',
svg_img_6=f'{image_list[6]}',
svg_img_7=f'{image_list[7]}'
)
elif length == 9:
return render_template(file_name,
title=name,
g_width=length * width,
width=width,
height=height,
x_position_0=position_list[0],
x_position_1=position_list[1],
x_position_2=position_list[2],
x_position_3=position_list[3],
x_position_4=position_list[4],
x_position_5=position_list[5],
x_position_6=position_list[6],
x_position_7=position_list[7],
x_position_8=position_list[8],
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
svg_img_2=f'{image_list[2]}',
svg_img_3=f'{image_list[3]}',
svg_img_4=f'{image_list[4]}',
svg_img_5=f'{image_list[5]}',
svg_img_6=f'{image_list[6]}',
svg_img_7=f'{image_list[7]}',
svg_img_8=f'{image_list[8]}',
)
elif length == 10:
return render_template(file_name,
title=name,
g_width=length * width,
width=width,
height=height,
x_position_0=position_list[0],
x_position_1=position_list[1],
x_position_2=position_list[2],
x_position_3=position_list[3],
x_position_4=position_list[4],
x_position_5=position_list[5],
x_position_6=position_list[6],
x_position_7=position_list[7],
x_position_8=position_list[8],
x_position_9=position_list[9],
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
svg_img_2=f'{image_list[2]}',
svg_img_3=f'{image_list[3]}',
svg_img_4=f'{image_list[4]}',
svg_img_5=f'{image_list[5]}',
svg_img_6=f'{image_list[6]}',
svg_img_7=f'{image_list[7]}',
svg_img_8=f'{image_list[8]}',
svg_img_9=f'{image_list[9]}'
)