Opened 16 years ago
Closed 12 years ago
#8135 closed New feature (wontfix)
Make RequestContext act as a dictionary
Reported by: | Marc Garcia | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When creating the context, using RequestContext to include context processors content, the next doesn't work:
context = dict(example=value) context.update(RequestContext(request))
instead I can use
context = requestContext(request) context.update(dict(example=value))
but I think that also allowing the first case would avoid some confusion.
Change History (9)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
milestone: | → post-1.0 |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
I ran into this as well, but don't know if it's a "good thing"
comment:3 by , 16 years ago
Triage Stage: | Design decision needed → Accepted |
---|
This is a valid point. The context is generally assumed to be a dictionary, so RequestContext should behave as such.
comment:4 by , 16 years ago
Triage Stage: | Accepted → Design decision needed |
---|
Ok, after a second thought, there's an easy way around this:
from django.template import Context context = Context(dict(example=value)) context.update(RequestContext(request))
comment:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:9 by , 12 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I don't see much gain in it -- especially since one usually passes RequestContext as context_instance and not via the normal dict.
This ticket makes not much sense to me. The Context is more than a simple dict, it is a stack container offering functions which cannot be easily emulated using a dict.
Although it would be possible to further emulate a dict I think this would send a wrong message to the user. Why would you want to construct a RequestContext, update a dict with it and then again create a Context to render the template?