1 Star 0 Fork 0

一块/chinese-poetry-db-web

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
server.py 3.40 KB
一键复制 编辑 原始数据 按行查看 历史
Harold-Y 提交于 2023-10-05 18:42 . 20231005 1842 first v finished
from flask import Flask, jsonify
import flask
from flask_cors import CORS, cross_origin
from db_backend import *
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route("/", methods=['GET'])
@cross_origin()
def home():
return "<p>Backend Active</p>"
@app.route("/search/poem", methods=['GET'])
@cross_origin()
def search_poem_controller():
args = dict(flask.request.args)
query_str = args['query_str']
query_type = args['query_type']
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(search_poem(query_str, query_type, items_per_page, curr_page))
@app.route("/query/poem_by_id", methods=['GET'])
@cross_origin()
def query_poem_by_id_controller():
args = dict(flask.request.args)
p_id = int(args['p_id'])
return jsonify(query_poem_by_id(p_id))
@app.route("/search/author", methods=['GET'])
@cross_origin()
def search_author_controller():
args = dict(flask.request.args)
query_str = args['query_str']
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(search_author(query_str, items_per_page, curr_page))
@app.route("/query/poem_by_author", methods=['GET'])
@cross_origin()
def query_poem_by_author_controller():
args = dict(flask.request.args)
a_id = args['a_id']
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(query_poem_by_author(a_id, items_per_page, curr_page))
@app.route("/display/author", methods=['GET'])
@cross_origin()
def display_author_controller():
args = dict(flask.request.args)
items_per_page = int(args.get('items_per_page', 100))
return jsonify(display_author(items_per_page))
@app.route("/display/rhythmic", methods=['GET'])
@cross_origin()
def display_rhythmic_controller():
args = dict(flask.request.args)
items_per_page = int(args.get('items_per_page', 100))
return jsonify(display_rhythmic(items_per_page))
@app.route("/search/rhythmic", methods=['GET'])
@cross_origin()
def search_rhythmic_controller():
args = dict(flask.request.args)
r_name = args['r_name']
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(search_rhythmic(r_name, items_per_page, curr_page))
@app.route("/query/poem_by_rhythmic", methods=['GET'])
@cross_origin()
def query_poem_by_rhythmic_controller():
args = dict(flask.request.args)
r_id = int(args['r_id'])
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(query_poem_by_rhythmic(r_id, items_per_page, curr_page))
@app.route("/display/collection", methods=['GET'])
@cross_origin()
def display_collection_controller():
return jsonify(display_collection())
@app.route("/query/poem_by_collection", methods=['GET'])
@cross_origin()
def query_poem_by_collection_controller():
args = dict(flask.request.args)
c_id = int(args['c_id'])
items_per_page = int(args.get('items_per_page', 100))
curr_page = int(args.get('curr_page', 1))
return jsonify(query_poem_by_collection(c_id, items_per_page, curr_page))
@app.route("/query/random_poem", methods=['GET'])
@cross_origin()
def query_random_poem_controller():
return jsonify(query_random_poem())
if __name__ == '__main__':
app.run()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zmhfly8/chinese-poetry-db-web.git
git@gitee.com:zmhfly8/chinese-poetry-db-web.git
zmhfly8
chinese-poetry-db-web
chinese-poetry-db-web
main

搜索帮助