Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#17913 closed Uncategorized (invalid)

'X' object has no attribute 'META' in RequestContext

Reported by: breton 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 breton 4 years ago.

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by breton

comment:1 Changed 4 years ago by breton

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Type changed from Uncategorized to Bug

comment:2 Changed 4 years ago by breton

  • Type changed from Bug to Uncategorized

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

comment:3 Changed 4 years ago by lukeplant

  • Resolution set to invalid
  • Status changed from new to 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 Changed 4 years ago by breton

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