代码拉取完成,页面将自动刷新
同步操作将从 辛菌桀/图书管理系统 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。