I’m puzzled with this behaviour. The code simply prints the type of the request. The first method works, but the second returns an empty string. The type of the class is django.corehandlers.wsgi.WSGIRequest.
(edit to clarify)
def someview(request):
html+="<p>type of the request each char "
for i in range(47):
html+= (str(type(request))[i])
html+="</p>"
html+="<p>type of the request each char "
for i in range(47):
html+= repr(str(type(request))[i])
html+="</p>"
return HttpResponse(html)
The result is the following. The second string is empty.
type of the request each char '<''c''l''a''s''s'' '"'"'d''j''a''n''g''o''.''c''o''r''e''.''h''a''n''d''l''e''r''s''.''w''s''g''i''.''W''S''G''I''R''e''q''u''e''s''t'"'"'>'
type of the request:
So your question is why is the second line not printing anything? The answer to that is that you need
repr(), notstr().However, you realize it will always be the same WSGIRequest, right? You are printing the representation of the class of the
requestobject.You probably want
request.METHOD.