Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

enter image description here

enter image description here

Something about Django Just as the photo show I don't know why there is has a 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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
193 views
Welcome To Ask or Share your Answers For Others

1 Answer

The problem is probably in your topic function. You assign one topic to the topics variable and then try to get an entry_set off a variable called topic instead of topics. Since you're only getting one topic it would make more sense to change the topics variable to singular 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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...