#22924 closed Cleanup/optimization (fixed)
MEDIA_URL needs TEMPLATE_CONTEXT_PROCESSORS
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It could be useful for beginners like me to know that without adding:
"django.core.context_processors.media",
to your TEMPLATE_CONTEXT_PROCESSORS, you will not get MEDIA_URL in your template. I found it easily on stack overflow though.
But it was not here:
Attachments (1)
Change History (9)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
I'm not sure, I think it is obvious to you that the problem is due to TEMPLATE_CONTEXT_PROCESSORS. But to a beginner, is obvious only what shows up using Google. And the two first pages that I found using "MEDIA_URL django" were the one you mentioned and the one I mentioned.
Also, even if the beginner is smarter than me and search for the template context processors,he'll google both "context_processors.media" or "django.core.context_processors.media", and find no explanation.
I thought static files was a better place to add some section about templates because it is more "focused", settings page looks like a big dictionary. But really it is up to you.
comment:3 by , 10 years ago
oh... I just got what you meant. Actually, I don't remember having modified these settings. Maybe inadvertently. Sorry, English is not my mother tongue.
comment:4 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
How about the attached patch?
by , 10 years ago
Attachment: | 22924.diff added |
---|
comment:6 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I'm not sure that's the best page for mentioning this as there's no example of referring to uploaded files in templates.
There's a warning in the settings docs: "Be careful when you override settings, especially when the default value is a non-empty tuple or dictionary, such as MIDDLEWARE_CLASSES and TEMPLATE_CONTEXT_PROCESSORS. Make sure you keep the components required by the features of Django you wish to use."
I think if you had seen that, you'd probably have looked at the initial
TEMPLATE_CONTEXT_PROCESSORS
list and checked what each of them did. What do you think?