我对这种行为感到困惑。该代码仅打印请求的类型。第一种方法有效,但第二种方法返回一个空字符串。类的类型是 django.corehandlers.wsgi.WSGIRequest。
(编辑澄清)
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)
结果如下。第二个字符串为空。
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: