Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#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)

requestcontext.diff (924 bytes ) - added by Boris Bobrov 13 years ago.

Download all attachments as: .zip

Change History (5)

by Boris Bobrov, 13 years ago

Attachment: requestcontext.diff added

comment:1 by Boris Bobrov, 13 years ago

Type: UncategorizedBug

comment:2 by Boris Bobrov, 13 years ago

Type: BugUncategorized

Well, now I am not so sure if it is a bug or something else.

comment:3 by Luke Plant, 13 years ago

Resolution: invalid
Status: newclosed

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 Boris Bobrov, 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 = ()
Note: See TracTickets for help on using tickets.
Back to Top