|
|
@ -123,8 +123,13 @@ class Flask(_PackageBoundObject): |
|
|
|
.. versionadded:: 0.11 |
|
|
|
.. versionadded:: 0.11 |
|
|
|
The `root_path` parameter was added. |
|
|
|
The `root_path` parameter was added. |
|
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.13 |
|
|
|
.. versionadded:: 1.0 |
|
|
|
The `host_matching` and `static_host` parameters were added. |
|
|
|
The ``host_matching`` and ``static_host`` parameters were added. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.0 |
|
|
|
|
|
|
|
The ``subdomain_matching`` parameter was added. Subdomain |
|
|
|
|
|
|
|
matching needs to be enabled manually now. Setting |
|
|
|
|
|
|
|
:data:`SERVER_NAME` does not implicitly enable it. |
|
|
|
|
|
|
|
|
|
|
|
:param import_name: the name of the application package |
|
|
|
:param import_name: the name of the application package |
|
|
|
:param static_url_path: can be used to specify a different path for the |
|
|
|
:param static_url_path: can be used to specify a different path for the |
|
|
@ -133,11 +138,13 @@ class Flask(_PackageBoundObject): |
|
|
|
:param static_folder: the folder with static files that should be served |
|
|
|
:param static_folder: the folder with static files that should be served |
|
|
|
at `static_url_path`. Defaults to the ``'static'`` |
|
|
|
at `static_url_path`. Defaults to the ``'static'`` |
|
|
|
folder in the root path of the application. |
|
|
|
folder in the root path of the application. |
|
|
|
:param host_matching: sets the app's ``url_map.host_matching`` to the given |
|
|
|
:param static_host: the host to use when adding the static route. |
|
|
|
value. Defaults to False. |
|
|
|
Defaults to None. Required when using ``host_matching=True`` |
|
|
|
:param static_host: the host to use when adding the static route. Defaults |
|
|
|
with a ``static_folder`` configured. |
|
|
|
to None. Required when using ``host_matching=True`` |
|
|
|
:param host_matching: set ``url_map.host_matching`` attribute. |
|
|
|
with a ``static_folder`` configured. |
|
|
|
Defaults to False. |
|
|
|
|
|
|
|
:param subdomain_matching: consider the subdomain relative to |
|
|
|
|
|
|
|
:data:`SERVER_NAME` when matching routes. Defaults to False. |
|
|
|
:param template_folder: the folder that contains the templates that should |
|
|
|
:param template_folder: the folder that contains the templates that should |
|
|
|
be used by the application. Defaults to |
|
|
|
be used by the application. Defaults to |
|
|
|
``'templates'`` folder in the root path of the |
|
|
|
``'templates'`` folder in the root path of the |
|
|
@ -347,6 +354,7 @@ class Flask(_PackageBoundObject): |
|
|
|
static_folder='static', |
|
|
|
static_folder='static', |
|
|
|
static_host=None, |
|
|
|
static_host=None, |
|
|
|
host_matching=False, |
|
|
|
host_matching=False, |
|
|
|
|
|
|
|
subdomain_matching=False, |
|
|
|
template_folder='templates', |
|
|
|
template_folder='templates', |
|
|
|
instance_path=None, |
|
|
|
instance_path=None, |
|
|
|
instance_relative_config=False, |
|
|
|
instance_relative_config=False, |
|
|
@ -530,6 +538,7 @@ class Flask(_PackageBoundObject): |
|
|
|
self.url_map = Map() |
|
|
|
self.url_map = Map() |
|
|
|
|
|
|
|
|
|
|
|
self.url_map.host_matching = host_matching |
|
|
|
self.url_map.host_matching = host_matching |
|
|
|
|
|
|
|
self.subdomain_matching = subdomain_matching |
|
|
|
|
|
|
|
|
|
|
|
# tracks internally if the application already handled at least one |
|
|
|
# tracks internally if the application already handled at least one |
|
|
|
# request. |
|
|
|
# request. |
|
|
@ -1977,19 +1986,30 @@ class Flask(_PackageBoundObject): |
|
|
|
return rv |
|
|
|
return rv |
|
|
|
|
|
|
|
|
|
|
|
def create_url_adapter(self, request): |
|
|
|
def create_url_adapter(self, request): |
|
|
|
"""Creates a URL adapter for the given request. The URL adapter |
|
|
|
"""Creates a URL adapter for the given request. The URL adapter |
|
|
|
is created at a point where the request context is not yet set up |
|
|
|
is created at a point where the request context is not yet set |
|
|
|
so the request is passed explicitly. |
|
|
|
up so the request is passed explicitly. |
|
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.6 |
|
|
|
.. versionadded:: 0.6 |
|
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 0.9 |
|
|
|
.. versionchanged:: 0.9 |
|
|
|
This can now also be called without a request object when the |
|
|
|
This can now also be called without a request object when the |
|
|
|
URL adapter is created for the application context. |
|
|
|
URL adapter is created for the application context. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 1.0 |
|
|
|
|
|
|
|
:data:`SERVER_NAME` no longer implicitly enables subdomain |
|
|
|
|
|
|
|
matching. Use :attr:`subdomain_matching` instead. |
|
|
|
""" |
|
|
|
""" |
|
|
|
if request is not None: |
|
|
|
if request is not None: |
|
|
|
return self.url_map.bind_to_environ(request.environ, |
|
|
|
# If subdomain matching is disabled (the default), use the |
|
|
|
server_name=self.config['SERVER_NAME']) |
|
|
|
# default subdomain in all cases. This should be the default |
|
|
|
|
|
|
|
# in Werkzeug but it currently does not have that feature. |
|
|
|
|
|
|
|
subdomain = ((self.url_map.default_subdomain or None) |
|
|
|
|
|
|
|
if not self.subdomain_matching else None) |
|
|
|
|
|
|
|
return self.url_map.bind_to_environ( |
|
|
|
|
|
|
|
request.environ, |
|
|
|
|
|
|
|
server_name=self.config['SERVER_NAME'], |
|
|
|
|
|
|
|
subdomain=subdomain) |
|
|
|
# We need at the very least the server name to be set for this |
|
|
|
# We need at the very least the server name to be set for this |
|
|
|
# to work. |
|
|
|
# to work. |
|
|
|
if self.config['SERVER_NAME'] is not None: |
|
|
|
if self.config['SERVER_NAME'] is not None: |
|
|
|