mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #24127 -- Changed the default current_app to the current namespace.
Changed the url template tag to use request.resolver_match.namespace as a default for the current_app argument if request.current_app is not set.
This commit is contained in:
committed by
Tim Graham
parent
6024fd5dc2
commit
bc7923beff
@@ -895,6 +895,12 @@ Miscellaneous
|
||||
whitespace by default. This can be disabled by setting the new
|
||||
:attr:`~django.forms.CharField.strip` argument to ``False``.
|
||||
|
||||
* If neither :attr:`request.current_app <django.http.HttpRequest.current_app>`
|
||||
nor :class:`Context.current_app <django.template.Context>` are set, the
|
||||
:ttag:`url` template tag will now use the namespace of the current request.
|
||||
Set ``request.current_app`` to ``None`` if you don't want to use a namespace
|
||||
hint.
|
||||
|
||||
.. _deprecated-features-1.9:
|
||||
|
||||
Features deprecated in 1.9
|
||||
|
||||
@@ -669,11 +669,16 @@ the fully qualified name into parts and then tries the following lookup:
|
||||
example, ``'polls'``). This will yield a list of instances of that
|
||||
application.
|
||||
|
||||
2. If there is a *current* application defined, Django finds and returns
|
||||
the URL resolver for that instance. The *current* application can be
|
||||
specified as an attribute on the request. Applications that expect to
|
||||
have multiple deployments should set the ``current_app`` attribute on
|
||||
the ``request`` being processed.
|
||||
2. If there is a current application defined, Django finds and returns the URL
|
||||
resolver for that instance. The current application can be specified with
|
||||
the ``current_app`` argument to the
|
||||
:func:`~django.core.urlresolvers.reverse()` function.
|
||||
|
||||
The :ttag:`url` template tag uses the namespace of the currently resolved
|
||||
view as the current application in a
|
||||
:class:`~django.template.RequestContext`. You can override this default by
|
||||
setting the current application on the :attr:`request.current_app
|
||||
<django.http.HttpRequest.current_app>` attribute.
|
||||
|
||||
.. versionchanged:: 1.8
|
||||
|
||||
@@ -682,8 +687,11 @@ the fully qualified name into parts and then tries the following lookup:
|
||||
:class:`~django.template.RequestContext` that is used to render a
|
||||
template.
|
||||
|
||||
The current application can also be specified manually as an argument
|
||||
to the :func:`~django.core.urlresolvers.reverse` function.
|
||||
.. versionchanged:: 1.9
|
||||
|
||||
Previously, the :ttag:`url` template tag did not use the namespace of the
|
||||
currently resolved view and you had to set the ``current_app`` attribute
|
||||
on the request.
|
||||
|
||||
3. If there is no current application. Django looks for a default
|
||||
application instance. The default application instance is the instance
|
||||
@@ -751,13 +759,6 @@ Using this setup, the following lookups are possible:
|
||||
|
||||
{% url 'polls:index' %}
|
||||
|
||||
Note that reversing in the template requires the ``current_app`` be added as
|
||||
an attribute to the ``request`` like this::
|
||||
|
||||
def render_to_response(self, context, **response_kwargs):
|
||||
self.request.current_app = self.request.resolver_match.namespace
|
||||
return super(DetailView, self).render_to_response(context, **response_kwargs)
|
||||
|
||||
* If there is no current instance - say, if we were rendering a page
|
||||
somewhere else on the site - ``'polls:index'`` will resolve to the last
|
||||
registered instance of ``polls``. Since there is no default instance
|
||||
|
||||
Reference in New Issue
Block a user