问题
This is follow up to the question from here bozo_exception in Django / feedparser
I would like to iterate through many feeds from models/DB and have each of them displayed in the html template. While I do understand that I need to iterate thought x.feed.entries in the html template, I assume that iteration through each rss source needs to happen in the view function correct?
def feed5(request):
source = Feed.objects.all()
for item in source.url:
rss = feedparser.parse(item)
context = {'rss': rss,}
return render(request, 'feedreader/feed5.html', context)
gives me this error: 'QuerySet' object has no attribute 'url'. Not sure how should I go about it?
thanks
回答1:
Well, it actually doesn't - Python isn't lying to you. See, source
is a QuerySet
, a list-like structure of results, not a single result. If it's your Feed
model that should have a url attribute, then look it up on it and not the query set:
for item in source:
rss = feedparser.parse(item.url)
来源:https://stackoverflow.com/questions/19078710/queryset-object-has-no-attribute-url-when-using-feedparser-in-django