Snippets are unofficial and unmaintained.
This is an archived view of user-submitted snippets. Despite being hosted on the Flask site, they are not official. No Flask maintainer has curated or checked the snippets for security, correctness, or design.
import flask class MyFlask(flask.Flask): @property def static_folder(self): if self.config.get('STATIC_FOLDER') is not None: return os.path.join(self.root_path, self.config.get('STATIC_FOLDER')) @static_folder.setter def static_folder(self, value): self.config.get('STATIC_FOLDER') = value # Now these are equivalent: app = Flask(__name__, static_folder='foo') app = MyFlask(__name__) app.config['STATIC_FOLDER'] = 'foo'
However since the URL rule is still created in __init__ this only work for setting a different path, not for disabling it completely with None.
# Still no static URL rule, /static/foo.png gives HTTP 404 app = MyFlask(__name__, static_folder=None) app.config['STATIC_FOLDER'] = 'foo' # /static/foo.png gives HTTP 500 rather than 404: app = Flask(__name__) app.config['STATIC_FOLDER'] = None
This snippet by Simon Sapin can be used freely for anything you like. Consider it public domain.