from exts import app from flask import render_template from user import user from display import display from exam import exam from manage import manage app.register_blueprint(user) app.register_blueprint(display) app.register_blueprint(exam) app.register_blueprint(manage) @app.errorhandler(405) def error_405(error): return render_template("405.html"), 405 @app.errorhandler(404) def error_404(error): return render_template("404.html"), 404 @app.errorhandler(500) def error_500(error): return render_template("500.html"), 500 if __name__ == '__main__': app.run(host="0.0.0.0", port=5000)
user_update(id,**user_info) users_info = user_all() return render_template('admin.html',users_info=users_info) else: error = "Password Error!" return render_template('update.html',user_info=user_select,error=error) else: return redirect(url_for('index')) # 删除 @app.route('/delete/') def user_del(): if session.get('user_id'): user_id = request.args.get('id') user_delete(user_id) users_info = user_all() return render_template('admin.html',users_info=users_info) else: return redirect(url_for('index')) # 首页 @app.route('/index/') def index(): if session.get('user_id'): session.clear() return render_template('login.html') if __name__=='__main__': app.run(host='0.0.0.0')
from exts import app from flask_cors import CORS from Blue.login import sign_in from Blue.index import index from Blue.china_detail import CN from Blue.news import news app.register_blueprint(sign_in, url_prefix='/sign_in') app.register_blueprint(index, url_prefix='/index') app.register_blueprint(CN, url_prefix='/cn') app.register_blueprint(news, url_prefix='/news') CORS(app, supports_credentials=True) if __name__ == '__main__': app.run(host='127.0.0.1', port=8080)
from exts import db,app bs = Bootstrap(app) @app.route("/") def hello(): return render_template("index.html") @app.route("/add", methods=['GET','POST']) def add(): form = InfoForm() if form.validate_on_submit(): data = form.getDataDict() schoolnum = Info.query.filter_by(name=data['schoolnum']).first() print(schoolnum) if schoolnum: flash(message="student id is exists") else: info = Info() for i in data: if hasattr(info, i): setattr(info, i, data[i]) db.session.add(info) db.session.commit() flash("commit successed!") return render_template("forms.html",form=form) if __name__ == "__main__": app.run(host="0.0.0.0",debug=True)
# coding:utf8 from flask import Flask import flask from exts import app @app.route('/') def hello_world(): return flask.render_template('index.html') if __name__ == '__main__': app.run(debug=True)
g.front_user = front_user @app.context_processor def add_g_to_template(): if hasattr(g, 'front_user'): return dict(front_user=g.front_user) else: return {} @app.errorhandler(401) def unpath_forbidden(error): if request.is_xhr: return xtjson.json_unpath_error('错误401,您的权限不足') else: return render_template('common/common_401.html'), 401 @app.errorhandler(404) def page_not_found(error): if request.is_xhr: return xtjson.json_unpath_error('错误404,您访问的页面未找到') else: return render_template('common/common_404.html'), 404 if __name__ == '__main__': app.run()