Django - How to pass a string value from the urlconf to feeds.py class
I'm struggling with something that I am sure has a very simple method, but I am not getting it right. I am trying to pass a value from the urlconf to the feeds.py file. What I am trying to do is generate specific feeds for comments on a page.
I have been reading the example in the documentation:
http://docs.djangoproject.com/en/dev/ref/contrib/syndication/
of how to use the get_object() method, but I cannot seem to pass the right values.
Here is what I have been trying. In the url.py file:
('^post/(?P<sl>.*)/comment_feed/$', CommentFeed()),
And in the feeds.py file:
class CommentFeed(Feed):
def get_object(self, request, sl):
return get_object_or_404(Post, ????)
And I keep getting a ValueError saying:
invalid literal for int() with base 10: 'Test-1'
What is the right way t开发者_StackOverflow社区o pass the object to the feeds CommnetFeed class?
Looks like you were testing it with post/Test-1/comment_feed/
- were you?
Django expects an integer as the post id. Give it a number as in post/12/comment_feed/
and use pk=sl
as done in the example given in the linked page.
return get_object_or_404(Post, pk=sl)
精彩评论