代码拉取完成,页面将自动刷新
from flask import Flask, render_template, request
from apps.controller.UserController import user_bp
from apps.pojo.Entitiy import db
from apps.service.LoginService import LoginService
app = Flask(__name__)
# 注册蓝图对象
app.register_blueprint(user_bp)
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:hy030812@{ipaddress}:{port}/{database}".format( ipaddress="localhost",port="3306",database="flask")
with app.app_context():
db.init_app(app)
# db.drop_all()
# db.create_all()
# class PhoneConverter(BaseConverter):
# regex = r'1[34578]\d{9}'
# app.url_map.converters['phone'] = PhoneConverter
#
# @app.route('/phone/<phone:phone>',methods=['GET'])
# def phone(phone):
# return f'phone:{phone}'
#
# # #方式一
# # app.config['TEMPLATES_AUTO_RELOAD'] = True
# # app.config['SECRET_KEY'] = '123@qee'
# # app.config['SQL_DEBUG'] =''
# # #方式二
# # app.config.update(
# # TEMPLATES_AUTO_RELOAD=True,
# # SECRET_KEY='123@qee',
# # SQL_DEBUG=''
# # )
# # #方式三
# # app.config.from_file('config.json',load=json.load)
@app.route('/')
def tologin():
return render_template('login.html')
@app.route('/login',methods=['POST'])
def dologin():
param = request.form
username = param.get('username')
password = param.get('password')
#调用登陆方法
user = LoginService.login(username,password)
if user:
return render_template('index.html',user=user)
else:
return render_template('login.html')
# @app.route('/index_resp')
# def index_resp(): # put application's code here
# resp = Response(response='Python&Flask',status=201,mimetype='text/plain')
# return resp
# @app.route('/dept/list')
# def dept_index(): # put application's code here
# name = 'hello'
# return render_template("index.html",name=name)
# @app.route('/hello/<num>')
# def hello(num):
# return 'hello ' + num
@app.route('/index_v1')
def index_v1(): # put application's code here
return render_template('index_v1.html')
@app.route('/index_v3')
def index_v3():
return render_template('index_v3.html')
if __name__ == '__main__':
app.run()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。