#29341 closed New feature (wontfix)
Automatically Set "request.current_app" for all Request
Reported by: | Luoxzhg | Owned by: | nobody |
---|---|---|---|
Component: | Utilities | Version: | dev |
Severity: | Normal | Keywords: | middleware, current_app, request |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django should provide a standrad middleware to add current_app attribute to request objects.
from django.utils.deprecation import MiddlewareMixin class CurrentAppMiddleware(MiddlewareMixin): def process_view(self, request, *args, **kwargs): namespace = request.resolver_match.namespace request.current_app = namespace if namespace elsel None
Change History (3)
comment:1 by , 7 years ago
Has patch: | set |
---|
comment:2 by , 7 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:3 by , 7 years ago
Some functions needs request.current_app to replace current_app argument 。
Add the attribute in every view function is repeatly.
Note:
See TracTickets
for help on using tickets.
Hi Luoxzhg,
Given you can already rely on
request.resolver_match.namespace
as you've demonstrated in your report I don't see the benefit of providing an alias that hides the fact this app name is actually bound to the URL reversal mechanism. IMHOrequest.resolver_match.namespace
does a good job at exposing this attribute while making its origin clear.Feel free to bring the discussion to developer mailing list if your disagree with my resolution.