Django:无法散列的类型:“列表”错误

时间:2018-07-30 23:00:51

标签: python django django-templates django-2.0

我正在研究Django 2项目。我有一个以前从未遇到过的错误。 HTML页面:

<body>
<h1>Postlar burada görüntüleniyor</h1>
<a href="{% url 'postlar:post_olustur' %}">Post Oluştur</a>
{% for post in listelenen_postlar %}
<br>
<a href="{% url 'postlar:post_detay' post.id  %}">{{post.başlık}}</a>
<br>
{{post.içerik}}
<br>
{{post.olusturma_zamanı}}/////////////////{{post.olusturma_zamanı|timesince}} ago
<br>
{{post.güncelleme_zamanı}}
<br>   
{% endfor %}

Views.py

def post_listele(request):
 listelenen_postlar = Post.objects.all()
 context ={"listelenen_postlar":listelenen_postlar}
 return render(request,"postlar/post_listele.html",context)

我的应用程序中的urls.py:

urlpatterns = [
url(r'^$',view=post_listele, name="post_listele"),
url(r'^post_olustur/$',view=post_olustur, name='post_olustur'),
url(r'^post_detay/(?P<id>[0-9]+)$',view=post_detay, name='post_detay'),]

这是错误:

TypeError at /postlar/
unhashable type: 'list'
Request Method: GET
Request URL:    http://127.0.0.1:8000/postlar/
Django Version: 2.0.7
Exception Type: TypeError
Exception Value:    
unhashable type: 'list'
Exception Location: C:\Users\mete\Desktop\blog_deneme\venv\lib\site-packages\django\db\models\sql\compiler.py in get_order_by, line 290
Python Executable:  C:\Users\mete\Desktop\blog_deneme\venv\Scripts\python.exe
Python Version: 3.6.4
Python Path:    
['C:\\Users\\mete\\Desktop\\blog_deneme\\blog',
 'C:\\Users\\mete\\Desktop\\blog_deneme\\venv\\Scripts\\python36.zip',
 'C:\\Users\\mete\\Desktop\\blog_deneme\\venv\\DLLs',
 'C:\\Users\\mete\\Desktop\\blog_deneme\\venv\\lib',
 'C:\\Users\\mete\\Desktop\\blog_deneme\\venv\\Scripts',
 'c:\\python\\Lib',
 'c:\\python\\DLLs',
 'C:\\Users\\mete\\Desktop\\blog_deneme\\venv',
 'C:\\Users\\mete\\Desktop\\blog_deneme\\venv\\lib\\site-packages']
Server time:    Mon, 30 Jul 2018 22:50:33 +0000

谢谢.. enter image description here

这是我的模型。py

class Post(models.Model):
başlık = models.CharField(max_length=120,blank=False,verbose_name="Başlık")
içerik = models.CharField(max_length=220,verbose_name="İçerik")
olusturma_zamanı = models.DateTimeField(auto_now_add=True)
güncelleme_zamanı = models.DateTimeField(auto_now=True)

def __str__(self):
    return "{}".format(self.başlık)
class Meta:
    verbose_name_plural="Gönderilerim"
    ordering = ["id"],

1 个答案:

答案 0 :(得分:0)

Django似乎无法理解如何订购查询集...

尝试从以下位置更改您的元类值:

ordering = ["id"],

ordering = ["id",]