From 047a07faada66c7e1717299b8f0df0011ae85f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E6=83=B3=E6=A9=A1=E7=9A=AE=E6=93=A6?= Date: Mon, 26 Dec 2022 11:41:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E6=AC=A1=E5=88=86=E9=A1=B5=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/__init__.py | 23 +++++- app/__pycache__/__init__.cpython-36.pyc | Bin 245 -> 467 bytes app/config.py | 13 ++++ app/model.py | 26 +++++++ app/school/__init__.py | 0 .../__pycache__/__init__.cpython-36.pyc | Bin 0 -> 133 bytes app/school/__pycache__/index.cpython-36.pyc | Bin 0 -> 1496 bytes app/school/index.py | 70 ++++++++++++++++++ app/templates/school/index.html | 59 +++++++++++++++ playground.py | 2 + 10 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 app/config.py create mode 100644 app/model.py create mode 100644 app/school/__init__.py create mode 100644 app/school/__pycache__/__init__.cpython-36.pyc create mode 100644 app/school/__pycache__/index.cpython-36.pyc create mode 100644 app/school/index.py create mode 100644 app/templates/school/index.html diff --git a/app/__init__.py b/app/__init__.py index d09516b..7be31a2 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,6 +1,27 @@ from flask import Flask +from flask_sqlalchemy import SQLAlchemy + +from .config import BaseConfig # 导入配置文件 app = Flask(__name__) +app.config.from_object(BaseConfig) # 启用配置 + +db = SQLAlchemy() +db.init_app(app) # 初始化数据库 + + +# 导入路由配置 from app import routes -from app import general \ No newline at end of file +from app import general +from .school.index import * + +app.register_blueprint(s) + + + + + + + + diff --git a/app/__pycache__/__init__.cpython-36.pyc b/app/__pycache__/__init__.cpython-36.pyc index 6804289f9fab064dcfc9fa734ed7d027c0204b79..7bac9ea0347df7c00172caf663da45e00fc93452 100644 GIT binary patch literal 467 zcmYk1y-ve05XbF&CrzM2yhK6j!iEsyLxKe%A(*U6R+?PX1Sbx5ipboT;1S@JvNCmL zWa1naEZymM_W%CpJ4ur0JN(GrDIs6v-?5M{F!U>?oa9uHnlefaTf(YsW+U6VBb?f0 zE+s(0+fwF(UpZ9(?iRIRZwU(_tRnDDjlHh$>j|5T>> z853m|W7Cnjei7-Po3inG@UqcIxuys>Z_*k#AMCVk*<__;&E>L!tYcQbWI@@K9mgl- zpK&KIZ9iR r_62Uyre?+{ zW}p~T4s$L`6bmCro*Bqyjba6|S%MifSziKmF=#U0Vs*<&EY1cp*oyK?OHzx0EcW!& zywsw^96wFAC|%YxkbDuywp$$W@p*~4sqyi*m=g;MikN|7MJzyKB|{NAh|NB^hS8pj N4anqS;$Y%o1OWOdD82vy diff --git a/app/config.py b/app/config.py new file mode 100644 index 0000000..6f197cb --- /dev/null +++ b/app/config.py @@ -0,0 +1,13 @@ +class BaseConfig(object): + DIALECT = 'mysql' + DRIVER = 'pymysql' + USERNAME = 'root' + PASSWORD = 'root' + HOST = '127.0.0.1' + PORT = '3306' + DATABASE = 'playground' + + SQLALCHEMY_DATABASE_URI = "{}+{}://{}:{}@{}:{}/{}?charset=utf8".format(DIALECT, DRIVER, USERNAME, PASSWORD, HOST, + PORT, DATABASE) + SQLALCHEMY_TRACK_MODIFICATIONS = False + SQLALCHEMY_ECHO = True diff --git a/app/model.py b/app/model.py new file mode 100644 index 0000000..abdcfd8 --- /dev/null +++ b/app/model.py @@ -0,0 +1,26 @@ +from app import db + + +class EntityBase(object): + def to_json(self): + fields = self.__dict__ + if "_sa_instance_state" in fields: + del fields["_sa_instance_state"] + + return fields + + +class School(db.Model, EntityBase): + """ + 表名,字段名 + """ + __tablename__ = "school_list" + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(255)) + province = db.Column(db.String(255)) + city = db.Column(db.String(255)) + feature = db.Column(db.String(255)) + hotValue = db.Column(db.String(255)) + pic = db.Column(db.String(255)) + category = db.Column(db.String(255)) + batchTimes = db.Column(db.String(255)) diff --git a/app/school/__init__.py b/app/school/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/school/__pycache__/__init__.cpython-36.pyc b/app/school/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..895f1886c6a846bead00f8d982aedb283b0725dc GIT binary patch literal 133 zcmXr!<>i|6cX=`c5IhDEFu(|8H~?`m3y?@*2xib^^jpbL1QJFNzl_|iVhSotGV=4{ ziwiPSQj6jXauO@ki}FkJQeqMd3Sx?rGxGCuV&da7^D;}~Y8OH z%z*1`bVXx4tSBh5BBFa($wgV$1^qkf;Kg)y=j44)`(AaBRMW3sy;twEepN3wo58)a zx4WO!2>F+s8V>NU!(Y4)gcD8^(!tqEXliw=lyz8YcWjC>1~RAP0B>_Aano9-Mv1Vv zD?DD~-ahO2+~>h{(g}p$uk-qh@&<2SCo|eO!thbr=-$;gHAmdEwTEED% zcx$X{Qd}8|Lba(rBSprA43$U+NuCM;Yo`WXF+LD{gusfmLv#ufq(Hb}acNw?N)lBiRzn^;VUWiMfb&py`n* z8$GWq69GJPdV$QWx5#@7Q+vYtY+}zSC0G7_mrNK~G{Lupy&e9H6)(fsha{u4va=dSx?Aw81W2}vq&09nn)IqJb?sLY1`UPBekvVu80%u z7-Q{5g8?A2?Pwca%JZs66 zfK)yMcDv3>5*MnAK5*bgu;DisVH+4l6zyAm#sQKuYX)FecHfx-`1|gRz(uGbsAtv` z;l*~C+yIR?Vcc%Pwdni6Ife^hx1HGlSbGA{#_y$B-UgOyJ|C@ zg!Xx)q7W0^Jy*43rE15vN)x=&(A*Ocw;P(lLm{yUZAY?KXx0--!dphP15bt=Yo`m% zRi=IuL_0~G#!9m&NhEfl?Nqru2fR5x`7Cmmkl>+JMBuv`bN}^&%;^QM35=_= page_obj["max_page"]: + page = page_obj["max_page"] + page_obj["next_page"] = page_obj["max_page"] + + page_obj["current_page"] = page + + if total == 0: + page_obj["offset"] = 0 + else: + page_obj["offset"] = (page_obj["current_page"] - 1) * page_obj["page_size"] + + page_range = [] + for i in range(1, page_obj["max_page"] + 1): + page_range.append(i) + page_obj["page_range"] = page_range + + return page_obj + + +@s.route('/list') +def list_school(): + # schools = School.query.all() + page = int(request.args.get("page", 1)) # 获取页码 + query = School.query + + total = query.count() # 获取数据总量 + pagination = Pagination(page, total) # 获取分页对象详细参数 + + if total != 0: + data_list = query.offset(pagination["offset"]).limit(pagination["page_size"]).all() + else: + data_list = [] + pagination["data_list"] = data_list + + return render_template('school/index.html', pagination=pagination) diff --git a/app/templates/school/index.html b/app/templates/school/index.html new file mode 100644 index 0000000..ee77ce3 --- /dev/null +++ b/app/templates/school/index.html @@ -0,0 +1,59 @@ + + + + + + 爬虫训练场,版权:梦想橡皮擦 + + + + + + +
+
+
+ 合计 {{pagination.total}} 条数据 + +
+
+
+ +
+
+

爬虫训练场 Copyright © 梦想橡皮擦

+ +
+ + + + \ No newline at end of file diff --git a/playground.py b/playground.py index 7971f1e..d10813f 100644 --- a/playground.py +++ b/playground.py @@ -2,5 +2,7 @@ from app import app # app.jinja_env.auto_reload = True app.config['TEMPLATES_AUTO_RELOAD'] = True + + if __name__ == '__main__': app.run(host='0.0.0.0', port=8888) -- GitLab