gpt4 book ai didi

python - Django:不可散列类型 :'list' 错误

转载 作者:太空宇宙 更新时间:2023-11-04 04:36:25 25 4
gpt4 key购买 nike

我正在从事 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 %}

View .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

这是我的model.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"],

最佳答案

看起来 Django 无法理解如何排序您的查询集...

尝试更改您的 Meta 类值:

ordering = ["id"],

ordering = ["id",]

关于python - Django:不可散列类型 :'list' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51603358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com