加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.py 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
hy 提交于 2024-12-06 11:39 . 12-6web
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化