Django:返回渲染哈希错误

时间:2016-12-08 13:11:21

标签: python django

我目前有以下代码:

url = "http://www.andes.ucmerced.edu/smap/backend/api/query\?    key\=9te21wWjfSZuq9aYqPqfwa3S8qBYAWP5zlav"
query = "select data in (now -1440minutes, now) where Metadata/Location/Building='Facilities A' and Metadata/Location/Room ='130' and Metada/Haystack/Tags ~ 'temp'"
r = requests.post(url, data=query).json()
query1 = "select data in (now -1440minutes, now) where Metadata/Location/Building='Facilities A' and Metadata/Location/Room ='130' and Metada/Haystack/Tags ~ 'flow'"
r1 = requests.post(url, data=query1).json()
query2 = "select * where Metadata/Location/Building='Facilities A' and Metadata/Location/Room ='130'"
r2 = requests.post(url, data=query2).json()
query3 = "select data in (now -1440minutes, now) where Metadata/Location/Building='Facilities A' and Metadata/Location/Room ='130'"
r3 = requests.post(url, data=query3).json()
N_func = []
for datum in r3:
    for datum1 in r2:
        if datum['uuid'] == datum1['uuid']:
            if len(datum['Readings']) == 0:
                N_func.append(datum1)
for datum in N_func:
    r = datum['Path'].split('/')
    datum['Path'] = r


return render(request, 'polls/room_130.html', {'Temp': r}, {'Flow': r1}, {'N_Func': N_func},)

我收到错误说

Traceback (most recent call last):
  File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 63, in __call__
return self.application(environ, start_response)
  File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 174, in __call__status = '%d %s' % (response.status_code,                             response.reason_phrase)
  File "C:\Python27\lib\site-packages\django\http\response.py", line 67, in reason_phrase
    return responses.get(self.status_code, 'Unknown Status Code')
TypeError: unhashable type: 'dict'
[08/Dec/2016 05:07:31] "GET /polls/layout/room_130/ HTTP/1.1" 500 59

请让我知道原因是什么。我尝试了一切。我试图将我正在渲染的对象更改为JSON。但它仍然无效。

1 个答案:

答案 0 :(得分:3)

您应该为模板上下文使用单个字典:

return render(request, 'polls/room_130.html', {'Temp': r, 'Flow': r1, 'N_Func': N_func})

您当前的代码相当于:

return render(request, 'polls/room_130.html', {'Temp': r}, content_type={'Flow': r1}, status={'N_Func': N_func}

这会导致错误,因为状态应该是整数(默认为200),而不是字典。