1 Star 0 Fork 1

lanpiawu/图书管理系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.py 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
from datetime import datetime, time
from flask import Flask, request, render_template, jsonify, flash, redirect, url_for, g, session
from sqlalchemy.sql.functions import current_user
import config
from exts import db
from bluePrints.admin import admin
from bluePrints.user import user
from bluePrints.book import book
from forms import NewStoreForm, BorrowForm, SearchStudentForm, StoreForm, ChangePasswordForm
from models import UserModel, AdminModel
from flask_migrate import Migrate
from forms import Login
app = Flask(__name__)
# 绑定配置文件
app.config.from_object(config)
db.init_app(app)
migrate = Migrate(app, db)
app.register_blueprint(admin)
app.register_blueprint(user)
app.register_blueprint(book)
@app.route('/')
def hello_world(): # put application's code here
form = Login()
return render_template("login.html", form=form)
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
form = Login()
return render_template('login.html', form=form)
elif request.method == 'POST':
form = Login()
if form.validate_on_submit():
account = UserModel.query.filter_by(account_number=form.account.data, password=form.password.data).first()
if account is None:
account = AdminModel.query.filter_by(account_number=form.account.data,
password=form.password.data).first()
if account is None:
flash(u'用户名或密码错误!')
return redirect(url_for('login'))
else:
session['account_id'] = account.account_number
return redirect(url_for('user.index'))
else:
session['account_id'] = account.account_number
return redirect(url_for('user.index'))
@app.route('/logout')
def logout():
session.clear()
return redirect('/')
@app.before_request
def before_login():
account_id = session.get('account_id')
if account_id:
account = UserModel.query.filter_by(account_number=account_id).first()
if account is None:
account = AdminModel.query.filter_by(account_number=account_id).first()
setattr(g, 'account', account)
else:
setattr(g, 'account', None)
@app.context_processor
def user_info():
return {'account': g.account}
if __name__ == '__main__':
app.run()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/lanpiawu/library-management-system.git
git@gitee.com:lanpiawu/library-management-system.git
lanpiawu
library-management-system
图书管理系统
master

搜索帮助