python - Flask-Talisman breaks Flask-Bootstrap
问题描述
I want my website to always redirect to the secure https version of the site, and I'm using flask-talisman
to do this. However for some reason adding this seemingly-unrelated line of code is breaking the flask-bootstrap
formatting on my website.
This is what the original __init__.py
file and website looked like before adding flask-talisman
:
from flask import Flask
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_bootstrap import Bootstrap
from flask_heroku import Heroku
app = Flask(__name__)
app.config.from_object(Config)
Bootstrap(app)
heroku = Heroku(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
from app import routes, models
And this is what the __init__.py
file and website look like after adding flask-talisman
:
from flask import Flask
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_talisman import Talisman
from flask_bootstrap import Bootstrap
from flask_heroku import Heroku
app = Flask(__name__)
app.config.from_object(Config)
Bootstrap(app)
Talisman(app)
heroku = Heroku(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
from app import routes, models
Changing the order of the lines Bootstrap(app)
and Talisman(app)
doesn't make any difference either. Any ideas? I want my website to be secure, but not at the cost of breaking all of the formatting.
解决方案
这是一个旧线程,但答案是您需要将允许的站点列入白名单,就像在这个例子中一样(直接来自烧瓶护身符网站):
csp = {
'default-src': [
'\'self\'',
'cdnjs.cloudflare.com'
]
}
talisman = Talisman(app, content_security_policy=csp)
推荐阅读
- django - ValidationError 未显示在模板中(尽管字段验证错误)
- reactjs - 如何将评级保存到本地存储,使其在刷新后不会消失?
- python - 可以采用 NaN 和 inf 值建议的线性回归库
- node.js - 试图从函数返回一个承诺的值
- swift - 迁移到 Combine 会导致 Snapshotlistener 失败
- python - 如何在远程 Linux shell(Python Admin SDK)中使用 Firebase Admin SDK 服务密钥 JSON 文件?
- swiftui - SwiftUI解码HTML实体报错:同时访问0x7ff43ff29b50,但修改需要独占访问
- python - pandas 数据帧中的对数回报 groupby 股票代码
- python - 如何使用 Python 和 matplotlib 绘制任意数学函数?
- html - 汉堡图标左对齐的响应式菜单