{"record":{"id":"659cfdf18dc82304","repo":"pallets/flask","slug":"static-folder-must-be-set-to-serve-static-files","errorCode":null,"errorMessage":"'static_folder' must be set to serve static_files.","messagePattern":"'static_folder' must be set to serve static_files\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/flask/app.py","lineNumber":406,"sourceCode":"        if isinstance(value, timedelta):\n            return int(value.total_seconds())\n\n        return value  # type: ignore[no-any-return]\n\n    def send_static_file(self, filename: str) -> Response:\n        \"\"\"The view function used to serve files from\n        :attr:`static_folder`. A route is automatically registered for\n        this view at :attr:`static_url_path` if :attr:`static_folder` is\n        set.\n\n        Note this is a duplicate of the same method in the Flask\n        class.\n\n        .. versionadded:: 0.5\n\n        \"\"\"\n        if not self.has_static_folder:\n            raise RuntimeError(\"'static_folder' must be set to serve static_files.\")\n\n        # send_file only knows to call get_send_file_max_age on the app,\n        # call it here so it works for blueprints too.\n        max_age = self.get_send_file_max_age(filename)\n        return send_from_directory(\n            t.cast(str, self.static_folder), filename, max_age=max_age\n        )\n\n    def open_resource(\n        self, resource: str, mode: str = \"rb\", encoding: str | None = None\n    ) -> t.IO[t.AnyStr]:\n        \"\"\"Open a resource file relative to :attr:`root_path` for reading.\n\n        For example, if the file ``schema.sql`` is next to the file\n        ``app.py`` where the ``Flask`` app is defined, it can be opened\n        with:\n\n        .. code-block:: python","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/pallets/flask/blob/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/app.py#L388-L424","documentation":"Raised by Scaffold.send_static_file() when the object has no static_folder configured. The method serves files out of static_folder via send_from_directory, so without a folder there is nothing to serve. This RuntimeError guards against a null/None path being passed to send_from_directory.","triggerScenarios":"Calling app.send_static_file('style.css') or blueprint.send_static_file(...) on an instance where static_folder was set to None (the default) or explicitly disabled. Happens if a Blueprint is constructed with static_folder=None and a static route/view still references it.","commonSituations":"Disabling static files via Flask(__name__, static_folder=None) or Blueprint('bp', __name__, static_folder=None) but still manually mounting or invoking the static view; copying a blueprint config that drops static_folder.","solutions":["Pass a static_folder when constructing the app/blueprint: Flask(__name__, static_folder='static').","If you intentionally disabled static files, remove the code path that calls send_static_file.","Check the value of app.static_folder / blueprint.has_static_folder before calling."],"exampleFix":"// before\napp = Flask(__name__, static_folder=None)\napp.send_static_file('style.css')  # raises\n// after\napp = Flask(__name__, static_folder='static')\napp.send_static_file('style.css')","handlingStrategy":"validation","validationCode":"if not getattr(app, 'has_static_folder', False):\n    raise RuntimeError('Cannot serve static files: static_folder is not set')\napp.send_static_file('style.css')","typeGuard":"def can_serve_static(obj) -> bool:\n    return bool(getattr(obj, 'has_static_folder', False))","tryCatchPattern":"try:\n    app.send_static_file(filename)\nexcept RuntimeError as e:\n    if 'static_folder' in str(e):\n        # serve fallback or 404\n        ...\n    raise","preventionTips":["Always pass static_folder when constructing Flask/Blueprint unless you intentionally disable static assets.","Centralize static-file serving behind a helper that checks has_static_folder first.","Document intent with a comment when setting static_folder=None."],"tags":["static-files","configuration","runtime-error"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}