Opened 7 years ago
Closed 7 years ago
#29597 closed Bug (invalid)
AttributeError when django.template.context_processors.debug is invoked with null request
| Reported by: | Eric Hellman | Owned by: | nobody |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
When the DjangoTemplates engine is used to render a template with a null request (for example, when used in render_to_string to render an email body) this line:
if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
raises an AttributeError: 'dict' object has no attribute 'META'
This should be replaced by:
if settings.DEBUG and request and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
otherwise, the debug context processor cannot be use for systems that render templates without a request.
Change History (2)
comment:1 by , 7 years ago
| Has patch: | unset |
|---|
comment:2 by , 7 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Sorry, my bug
this was caused by code that looked like this:
context = {a_dict}
render_to_string(template_name, {another_dict}, context)
because the signature of the method is
def render_to_string(template_name, context=None, request=None, using=None)
I missed that request was getting another_dict.
the code was originally targeted at the 1.5.12 signature
render_to_string(template_name, dictionary=None, context_instance=None)
but it worked in 1.8, and didn't break till 1.11.
Can you give the code you're using? At first glance, I'd say that perhaps you've made a mistake by using
render_to_string()withRequestContextinstead of a plain dictionary but that could be an incorrect guess.