MCPcopy
hub / github.com/pallets/flask / __init__

Method __init__

src/flask/app.py:226–279  ·  view source on GitHub ↗
(
        self,
        import_name: str,
        static_url_path: str | None = None,
        static_folder: str | os.PathLike[str] | None = "static",
        static_host: str | None = None,
        host_matching: bool = False,
        subdomain_matching: bool = False,
        template_folder: str | os.PathLike[str] | None = "templates",
        instance_path: str | None = None,
        instance_relative_config: bool = False,
        root_path: str | None = None,
    )

Source from the content-addressed store, hash-verified

224 session_interface: SessionInterface = SecureCookieSessionInterface()
225
226 def __init__(
227 self,
228 import_name: str,
229 static_url_path: str | None = None,
230 static_folder: str | os.PathLike[str] | None = "static",
231 static_host: str | None = None,
232 host_matching: bool = False,
233 subdomain_matching: bool = False,
234 template_folder: str | os.PathLike[str] | None = "templates",
235 instance_path: str | None = None,
236 instance_relative_config: bool = False,
237 root_path: str | None = None,
238 ):
239 super().__init__(
240 import_name=import_name,
241 static_url_path=static_url_path,
242 static_folder=static_folder,
243 static_host=static_host,
244 host_matching=host_matching,
245 subdomain_matching=subdomain_matching,
246 template_folder=template_folder,
247 instance_path=instance_path,
248 instance_relative_config=instance_relative_config,
249 root_path=root_path,
250 )
251
252 #: The Click command group for registering CLI commands for this
253 #: object. The commands are available from the ``flask`` command
254 #: once the application has been discovered and blueprints have
255 #: been registered.
256 self.cli = cli.AppGroup()
257
258 # Set the name of the Click group in case someone wants to add
259 # the app's commands to another CLI tool.
260 self.cli.name = self.name
261
262 # Add a static route using the provided static_url_path, static_host,
263 # and static_folder if there is a configured static_folder.
264 # Note we do this without checking if static_folder exists.
265 # For one, it might be created while the server is running (e.g. during
266 # development). Also, Google App Engine stores static files somewhere
267 if self.has_static_folder:
268 assert bool(static_host) == host_matching, (
269 "Invalid static_host/host_matching combination"
270 )
271 # Use a weakref to avoid creating a reference cycle between the app
272 # and the view function (see #3761).
273 self_ref = weakref.ref(self)
274 self.add_url_rule(
275 f"{self.static_url_path}/<path:filename>",
276 endpoint="static",
277 host=static_host,
278 view_func=lambda **kw: self_ref().send_static_file(**kw), # type: ignore
279 )
280
281 def get_send_file_max_age(self, filename: str | None) -> int | None:
282 """Used by :func:`send_file` to determine the ``max_age`` cache

Callers

nothing calls this directly

Calls 2

add_url_ruleMethod · 0.45
send_static_fileMethod · 0.45

Tested by

no test coverage detected