django类型错误无法连接str和deferred属性对象

时间:2016-12-02 21:13:32

标签: python django

在代码中,我连接到我的数据库并创建一堆链接。我在这里遵循教程:https://www.youtube.com/watch?v=b0d09mYsORs

代码按原样,教师可以运行代码。我不是。

我不确定延迟对象是什么,以及问题可能是什么。我已经阅读了一段时间的文档,并且在我继续推动的同时请求一些帮助。

代码:

def index(request):
    allAlbums = Album.objects.all()
    html = ''
    for album in allAlbums:
        url = '/music/' + str(album.id) + '/'
        html += '<a href ="' + url + '">' + Album.albumTitle + '</a><br>'
    return HttpResponse(html)

当我尝试将Album.albumTitle属性转换为字符串时,我收到零内容。

3 个答案:

答案 0 :(得分:3)

SIZE((node)-[:has_card]->())中的

Album应为小写,否则您正在访问该类,而不是您想要的特定实例。

更正后的代码:

Album.albumTitle

答案 1 :(得分:-1)

使用与上面一行相同的技巧。改变:

div {
  margin: 0em;
  padding: 2em;
}
#source {
  color: blue;
  border: 1px solid black;
}
#target {
  border: 1px solid black;
}

为:

<div>
  <p id="source" ondragstart="dragstart_handler(event);" draggable="true">
    Select this element, drag it to the Drop Zone and then release the selection to move the element.</p>
</div>
<div id="target" ondrop="drop_handler(event);" ondragover="dragover_handler(event);">Drop Zone</div>

答案 2 :(得分:-1)

def index(request):
    allAlbums = Album.objects.all()
    html = ''
    for album in allAlbums:
        url = '/music/' + str(album.id) + '/'
        html += '<a href ="' + url + '">' + album.albumTitle + '</a><br>'
    return HttpResponse(html)

这对我有用,我遇到了同样的问题,并且关注Bucky。因为专辑是