Opened 5 years ago

Closed 4 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: master
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 Changed 5 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

I felt awkward when I added that documentation.

comment:2 Changed 5 years ago by Aymeric Augustin

Keywords: multiple-template-engines removed

comment:3 Changed 5 years ago by Aymeric Augustin

Keywords: current_app added

comment:4 Changed 4 years ago by Marten Kenbeek

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

comment:5 Changed 4 years ago by Tim Graham

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:6 Changed 4 years ago by Marten Kenbeek

comment:7 Changed 4 years ago by Marten Kenbeek <marten.knbk@…>

In 6364df6:

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

comment:8 Changed 4 years ago by Tim Graham <timograham@…>

In ae93aee:

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

Backport of 6364df68879efc0d9451d6427e34b4542e3d7e0b from master

comment:9 Changed 4 years ago by Tim Graham

Has patch: set
Needs tests: set

comment:10 Changed 4 years ago by Marten Kenbeek

Needs tests: unset

comment:11 Changed 4 years ago by Tim Graham <timograham@…>

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