{"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":405,"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":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/pallets/flask/blob/6a2f545bfd8ed31e19066a299296917e034aca58/src/flask/app.py#L387-L423","documentation":"Raised by `send_static_file()` (src/flask/app.py:405) when `has_static_folder` is false, i.e. the app or blueprint was created with `static_folder=None`. Flask only registers and serves the static view when a static folder is configured, so requesting a static file without one is a programming/configuration error, not a 404.","triggerScenarios":"Calling `app.send_static_file(name)` or `blueprint.send_static_file(name)` directly (or via `url_for('static', ...)` hitting the static endpoint) on a `Flask(__name__, static_folder=None)` app or a `Blueprint(...)` created without a `static_folder` argument (blueprints default to None, unlike the app).","commonSituations":"Blueprints are the classic case — developers assume blueprints serve static files like the app does, but `Blueprint` has no default static folder. Also hit when disabling static serving for API-only apps (`static_folder=None`) while templates still call `url_for('static', ...)`, or when a custom view delegates to `send_static_file`.","solutions":["Pass `static_folder='static'` (and optionally `static_url_path`) when constructing the `Flask` app or `Blueprint`.","For blueprints, remember the static folder path is relative to the blueprint's `root_path` — verify the directory actually exists.","If the app is intentionally API-only, remove the `url_for('static', ...)` references or the direct `send_static_file` call instead of re-enabling static serving.","For one-off files outside a static folder, use `flask.send_from_directory(directory, filename)` directly."],"exampleFix":"# before\nbp = Blueprint(\"admin\", __name__)\n\n# after\nbp = Blueprint(\"admin\", __name__, static_folder=\"static\", static_url_path=\"/admin/static\")","handlingStrategy":"validation","validationCode":"if app.static_folder is None:\n    raise RuntimeError('configure static_folder before calling send_static_file')","typeGuard":"def has_static_folder(app) -> bool:\n    return app.static_folder is not None","tryCatchPattern":null,"preventionTips":["If you created the app with `Flask(__name__, static_folder=None)`, do not register routes that call `send_static_file`","Check `app.has_static_folder` before serving static assets programmatically","Serve custom static locations with `send_from_directory` and an explicit path instead"],"tags":["flask","static-files","blueprint","configuration"],"analyzedSha":"6a2f545bfd8ed31e19066a299296917e034aca58","analyzedAt":"2026-07-31T19:13:49.921Z","schemaVersion":2}