#17913 closed Uncategorized (invalid)
'X' object has no attribute 'META' in RequestContext
Reported by: | Boris Bobrov | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
def v2(request): t = Template('') c = RequestContext('notarequest') return HttpResponse(t.render(c))
returns
AttributeError at /v2/ 'str' object has no attribute 'META'
Maybe it should be TypeError with value "the first argument should be HttpRequest object, not str"?
Attachments (1)
Change History (5)
by , 13 years ago
Attachment: | requestcontext.diff added |
---|
comment:1 by , 13 years ago
Type: | Uncategorized → Bug |
---|
comment:2 by , 13 years ago
Type: | Bug → Uncategorized |
---|
comment:3 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
There is no Pythonic way to test for a HttpRequest
object that fits with duck-typing. In fact, if you set TEMPLATE_CONTEXT_PROCESSORS to an empty list the above code will succeed, and this tolerance could be useful in some testing situations or other situations where you are not using a Django HttpRequest
object. So there is nothing RequestContext
can do here.
comment:4 by , 13 years ago
So, the check must be in every context processor?
If TEMPLATE_CONTEXT_PROCESSORS = (), then we get
Exception Type: AttributeError Exception Value: 'SafeUnicode' object has no attribute 'status_code' Exception Location: django/http/utils.py in conditional_content_removal, line 28
because response == u
my settings.py:
MIDDLEWARE_CLASSES = ( # 'django.middleware.common.CommonMiddleware', # 'django.contrib.sessions.middleware.SessionMiddleware', # 'django.middleware.csrf.CsrfViewMiddleware', # 'django.contrib.auth.middleware.AuthenticationMiddleware', # 'django.contrib.messages.middleware.MessageMiddleware', ) TEMPLATE_CONTEXT_PROCESSORS = ()
Well, now I am not so sure if it is a bug or something else.