Python 错误:不可损坏的类型:“dict”
我对Django有问题: 我无法在表中显示mysql数据库中的数据。我看到错误异常值:unhable类型:“dict” 这是我的代码: views.py:Python 错误:不可损坏的类型:“dict”,python,mysql,django,Python,Mysql,Django,我对Django有问题: 我无法在表中显示mysql数据库中的数据。我看到错误异常值:unhable类型:“dict” 这是我的代码: views.py: List_of_date=El.objects.all() return HttpResponse(template.render(context),args, {'List_of_date': List_of_date}) models.py: class El(models.Model): id_ch=models.Intege
List_of_date=El.objects.all()
return HttpResponse(template.render(context),args, {'List_of_date': List_of_date})
models.py:
class El(models.Model):
id_ch=models.IntegerField()
TXT = models.CharField(max_length=200)
模板:
<table>
<thead>
<tr>
<th>№</th>
<th>Text</th>
</tr>
</thead>
<tbody>
{% for i in List_of_date %}
<tr>
<td class="center">{{ i.id_ch }}</td>
<td class="center">{{ i.TXT }}</td>
</tr>
{% endfor %}
</tbody>
</table>
有人能帮我吗?您正在向HttpResponse构造函数传递错误的参数 签名是
HttpResponse.__init__(content='', content_type=None, status=200, reason=None, charset=None)
我认为您应该使用{'List\u of_date':List\u of_date}作为模板呈现的上下文。
所以你想调用一些东西,比如我不知道你的args变量是什么
return HttpResponse(template.render(Context({'List_of_date': List_of_date})))
通常什么时候会出现不可修复的类型:“dict”错误
当您尝试使用字典作为键在另一个字典中执行查找时,会出现此错误
例如:
In [1]: d1 = {'a':1, 'b':2}
In [2]: d2 = {'c':3}
In [3]: d2[d1] # perform lookup with key as dictionary 'd1'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-163d2a314f4b> in <module>()
----> 1 d2[d1]
TypeError: unhashable type: 'dict'
你能给我们这个错误消息的完整回溯吗。但是实际上op应该使用呈现快捷方式。我使用变量args就像术语词典args={}args['username']=auth.get_userrequest.username args['shedulelectform']='true'template=loader.get_template'template.html'当我写入时:return HttpResponsetemplate.renderContext{'List_of_date':List_of_date}我看到错误'RequestContext'对象不可调用请使用呈现快捷方式。
return render(template_name, {'List_of_date': List_of_date})