Python flask_wtf 模块,CSRFProtect() 实例源码
我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用flask_wtf.CSRFProtect()。
def create_app(config_name):
global user_datastore
app = Flask(__name__)
app.config.from_object(app_config[config_name])
csrf = CSRFProtect()
csrf.init_app(app)
assets = Environment(app)
create_assets(assets)
via = Via()
via.init_app(app)
# Code for desmostration the flask upload in several models - - - -
from user import user_photo
from restaurant import restaurant_photo
from food import food_photo
configure_uploads(app, (restaurant_photo, food_photo, user_photo))
engine = create_engine(app.config['sqlALCHEMY_DATABASE_URI'])
if not database_exists(engine.url):
create_database(engine.url)
security = Security(app, user_datastore, register_form=SecurityRegisterForm)
create_security_admin(app=app, path=os.path.join(os.path.dirname(__file__)))
with app.app_context():
db.init_app(app)
db.create_all()
user_datastore.find_or_create_role(name='admin', description='Administrator')
db.session.commit()
user_datastore.find_or_create_role(name='end-user', description='End user')
db.session.commit()
@app.route('/', methods=['GET'])
@app.route('/home', methods=['GET'])
def index():
return render_template('index.html')
@app.errorhandler(403)
def forbidden(error):
return render_template('error/403.html', title='Forbidden'), 403
@app.errorhandler(404)
def page_not_found(error):
return render_template('error/404.html', title='Page Not Found'), 404
@app.errorhandler(500)
def internal_server_error(error):
db.session.rollback()
return render_template('error/500.html', title='Server Error'), 500
return app
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。