open_resource() — flask Function Reference
Architecture documentation for the open_resource() function in blueprints.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD 08a1740c_dd5d_29d7_d959_c916e58e9e8c["open_resource()"] 43802377_8224_2289_2f49_1129adf043ee["Blueprint"] 08a1740c_dd5d_29d7_d959_c916e58e9e8c -->|defined in| 43802377_8224_2289_2f49_1129adf043ee style 08a1740c_dd5d_29d7_d959_c916e58e9e8c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/blueprints.py lines 104–128
def open_resource(
self, resource: str, mode: str = "rb", encoding: str | None = "utf-8"
) -> t.IO[t.AnyStr]:
"""Open a resource file relative to :attr:`root_path` for reading. The
blueprint-relative equivalent of the app's :meth:`~.Flask.open_resource`
method.
:param resource: Path to the resource relative to :attr:`root_path`.
:param mode: Open the file in this mode. Only reading is supported,
valid values are ``"r"`` (or ``"rt"``) and ``"rb"``.
:param encoding: Open the file with this encoding when opening in text
mode. This is ignored when opening in binary mode.
.. versionchanged:: 3.1
Added the ``encoding`` parameter.
"""
if mode not in {"r", "rt", "rb"}:
raise ValueError("Resources can only be opened for reading.")
path = os.path.join(self.root_path, resource)
if mode == "rb":
return open(path, mode) # pyright: ignore
return open(path, mode, encoding=encoding)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does open_resource() do?
open_resource() is a function in the flask codebase, defined in src/flask/blueprints.py.
Where is open_resource() defined?
open_resource() is defined in src/flask/blueprints.py at line 104.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free