2017-02-18 164 views
-1

enter image description here函數對象有沒有屬性 'entry_set'

enter image description here

一些關於Django的 正如照片顯示 我不知道爲什麼會出現有一個AttributeError的

from django.shortcuts import render 
from .models import Topic 
def topic(request, topic_id): 
    topics = Topic.objects.get(id=topic_id) 
    entries = topic.entry_set.order_by('-date_added') 
    context = {'topic': topic, 'entries': entries} 
return render(request, 'learning_logs/topic.html', context) 
+0

請提供的示例代碼和錯誤輸出直接在這裏並沒有外部圖像源。你的問題標題也不是描述性的。它應該告訴關於這個問題的一些事 – dahrens

+0

我已經添加了代碼。 –

回答

1

問題可能在你的主題功能。你一個題目分配給topics變量,然後設法弄一本entry_set關閉了一個名爲topic,而不是topics變量。既然你只得到一個題目會更有意義的topics變量更改爲單數topic

def topic(request, topic_id): 
    topic = Topic.objects.get(id=topic_id) 
    entries = topic.entry_set.order_by('-date_added') 
    context = {'topic': topic, 'entries': entries} 
    return render(request, 'learning_logs/topic.html', context)