Opened 6 years ago

Closed 6 years ago

Last modified 6 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: master
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


def v2(request):
    t = Template('')
    c = RequestContext('notarequest')
    return HttpResponse(t.render(c))


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 6 years ago.

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by Boris Bobrov

Attachment: requestcontext.diff added

comment:1 Changed 6 years ago by Boris Bobrov

Type: UncategorizedBug

comment:2 Changed 6 years ago by Boris Bobrov

Type: BugUncategorized

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

comment:3 Changed 6 years ago by Luke Plant

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 Changed 6 years ago by Boris Bobrov

So, the check must be in every context processor?

Exception Type: 	AttributeError
Exception Value: 	'SafeUnicode' object has no attribute 'status_code'
Exception Location: 	django/http/ in conditional_content_removal, line 28

because response == u


#    'django.middleware.common.CommonMiddleware',
#    'django.contrib.sessions.middleware.SessionMiddleware',
#    'django.middleware.csrf.CsrfViewMiddleware',
#    'django.contrib.auth.middleware.AuthenticationMiddleware',
#    'django.contrib.messages.middleware.MessageMiddleware',

Note: See TracTickets for help on using tickets.
Back to Top