gpt4 book ai didi

python - 不可哈希类型 : 'list'

转载 作者:行者123 更新时间:2023-12-01 06:29:32 25 4
gpt4 key购买 nike

我正在将应用程序从 django 1.8 和 python 2.7 移植到 django 2.2 和 PYTHON 3.6

这是在 python 2.7 中

 def get_absolute_url(self):
return ('threads_reply', [self.id])
get_absolute_url = models.permalink(get_absolute_url)

我也改了

def get_absolute_url(self):
return django.urls.resolve('threads_reply', [self.id])

现在它崩溃了

@login_required
def inbox(request, template_name='django_messages/inbox.html'):
"""
Displays a list of received messages for the current user.
Optional Arguments:
``template_name``: name of the template to use.
"""
thread_list = Thread.objects.inbox_for(request.user)
return render(request, template_name, {
'thread_list': thread_list,
})

最佳答案

resolve()不期望列表作为第二个参数。该函数用于解析相应 View 函数的 URL 路径,例如:

match = resolve('/some/path/')
# Print the URL pattern that matches the URL
print(match.url_name)

对于你的情况,我想你正在寻找 reverse :

from django.urls import reverse

def get_absolute_url(self):
reverse('threads_reply', args=[self.id])

这做相反的事情。它将 View 名称反转为 URL。

关于python - 不可哈希类型 : 'list' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59971427/

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