|
@@ -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
|