from datetime import timedelta from admin.admin import admin from user.user import user from company.company import company from company.export import * # app=Flask(__name__) app.config['JSON_AS_ASCII'] = False app.config['SECRET_KEY']=os.urandom(24) #设置为24位的字符,每次运行服务器都是不同的,所以服务器启动一次上次的session就清除。 app.config['PERMANENT_SESSION_LIFETIME']=timedelta(hours=1) #设置session的保存时间。 #添加数据到session #操作的时候更操作字典是一样的 app.register_blueprint(admin,url_prefix='/admin') app.register_blueprint(user, url_prefix='/user') app.register_blueprint(company, url_prefix='/p') def exportCompany(): start = 10362 end = 10363 resultExport = export(start,end) # 返回结果{"flag": True, "tips": "没有从数据库中获取数据,可能行号过大","path":""} # target_path = "" # if(resultExport["flag"]): # return send_from_directory(target_path, resultExport["path"], as_attachment=True) # else: # return jsonify(resultExport) print(resultExport)
@app.route('/presentations/<presentation_id>/delete', methods=["GET"]) @login_required @instructor_required def delete_presentation(presentation_id): presentation = Presentation.query.get(presentation_id) db.session.delete(presentation) db.session.commit() return redirect( url_for('list_presentations', course_id=presentation.course_id)) uploads = Blueprint('uploads', __name__, url_prefix='/uploads') @uploads.route('/<setname>/<path:filename>') @login_required def show(setname, filename): config = current_app.upload_set_config.get(setname) if config is None: abort(404) if g.user.has_permission_to_read(setname, filename): return send_from_directory(config.destination, filename) else: abort(403) app.register_blueprint(uploads) if __name__ == '__main__': app.run('0.0.0.0', debug=True, ssl_context='adhoc')
from flask import Response, jsonify, request from models.AdminModel import AdminModel from views.Auth import requires_auth from db import app, db import views # Register sub views. app.register_blueprint(views.Heartbeat.bp) app.register_blueprint(views.Kiosk.bp) app.register_blueprint(views.Parent.bp) app.register_blueprint(views.Child.bp) app.register_blueprint(views.Entry.bp) app.register_blueprint(views.Admin.bp) @app.route('/login') @requires_auth def login(): auth = request.authorization admin = db.session.query(AdminModel).filter_by(email=auth.username).first() return jsonify(admin.as_dict()) if __name__ == '__main__': app.run()