Use route Flask-Talisman on Blueprint specific routes

Viewed 52

How can I use Flask-Talisman per-view options with a Flask Blueprints? As per the repo: https://github.com/GoogleCloudPlatform/flask-talisman#per-view-options But I have a main module and views module like this:

Here is main.py:

from flask import Flask
from flask_talisman import Talisman

from views import views

app = Flask(__name__)

app.register_blueprint(views)

csp = {
    "default-src": [
        "'unsafe-eval'",
        "'self'",
        "'unsafe-inline'",
    ],
}

talisman = Talisman(app, force_https=False, content_security_policy=csp)

Here is views.py:

from flask import Blueprint

from main import talisman

general = Blueprint("general", __name__)


@general.get("/ping")
@talisman(frame_options=None, frame_options_allow_from="https://exmple.com/")
def ping():
    return "pong"

If I try to do it this way it gives me import error on views.py trying to import talisman, I guess due to circular import?

Is there a way to place @talisman(frame_options=None, frame_options_allow_from="https://exmple.com/") option on all the routes from the views blueprint?

0 Answers
Related