Opened 10 years ago

Closed 9 years ago

#24127 closed New feature (fixed)

Automatically set the current URL namespace based on the URL of the current request

Reported by: Aymeric Augustin Owned by: Marten Kenbeek
Component: Core (URLs) Version: dev
Severity: Normal Keywords: current_app
Cc: marten.knbk@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation on URL namespaces shows the following example:

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)

self.request.current_app = self.request.resolver_match.namespace looks like something that makes sense in general and could be done automatically for all requests.

This became possible in Django 1.8 because current_app is now an attribute of the request object.

There are some fairly obvious backwards-compatibility concerns, but this change looks like it could save a lot of boilerplate code.

Change History (11)

comment:1 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

I felt awkward when I added that documentation.

comment:2 by Aymeric Augustin, 10 years ago

Keywords: multiple-template-engines removed

comment:3 by Aymeric Augustin, 10 years ago

Keywords: current_app added

comment:4 by Marten Kenbeek, 9 years ago

Cc: marten.knbk@… added
Owner: changed from nobody to Marten Kenbeek
Status: newassigned

comment:5 by Tim Graham, 9 years ago

Marten, do you plan to move forward with this ticket? It should ease the deprecation in #24126 a bit as I noted there, I think.

comment:7 by Marten Kenbeek <marten.knbk@…>, 9 years ago

In 6364df6:

Refs #24127 -- Added documentation for HttpRequest.current_app.

comment:8 by Tim Graham <timograham@…>, 9 years ago

In ae93aee:

[1.8.x] Refs #24127 -- Added documentation for HttpRequest.current_app.

Backport of 6364df68879efc0d9451d6427e34b4542e3d7e0b from master

comment:9 by Tim Graham, 9 years ago

Has patch: set
Needs tests: set

comment:10 by Marten Kenbeek, 9 years ago

Needs tests: unset

comment:11 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In bc7923b:

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.

Note: See TracTickets for help on using tickets.
Back to Top