Winer provides the same API as django’s syndication Feed class, adapted to a Philo-style MultiView for easy database management. Apps that need syndication can simply subclass FeedView, override a few methods, and start serving RSS and Atom feeds. See BlogView for a concrete implementation example.
FeedView is an abstract model which handles a number of pages and related feeds for a single object such as a blog or newsletter. In addition to all other methods and attributes, FeedView supports the same generic API as django.contrib.syndication.views.Feed.
The suffix which will be appended to a page URL for a feed_type feed of its items. Default: “feed”. Note that RSS and Atom feeds will always be available at <page_url>/rss and <page_url>/atom regardless of the value of this setting.
See also
A BooleanField - whether or not feeds are enabled.
A PositiveIntegerField - the maximum number of items to return for this feed. All items will be returned if this field is blank. Default: 15.
A ForeignKey to a Template which will be used to render the title of each item in the feed if provided.
A ForeignKey to a Template which will be used to render the description of each item in the feed if provided.
An attribute holding the name of the context variable to be populated with the items managed by the FeedView. Default: “items”
An attribute holding the name of the attribute on a subclass of FeedView which will contain the main object of a feed (such as a Blog.) Default: “object”
Example:
class BlogView(FeedView):
blog = models.ForeignKey(Blog)
object_attr = 'blog'
item_context_var = 'entries'
An attribute holding a description of the feeds served by the FeedView. This is a required part of the django.contrib.syndication.view.Feed API.
Given the name to be used to reverse this view and the names of the attributes for the function that fetches the objects, returns patterns suitable for inclusion in urlpatterns. In addition to base (which will serve the page at page_attr) and base + feed_suffix (which will serve a feed_type feed), patterns will be provided for each registered feed type as base + slug.
Parameters: |
|
---|---|
Returns: | Patterns suitable for use in urlpatterns. |
Example:
class BlogView(FeedView):
blog = models.ForeignKey(Blog)
entry_archive_page = models.ForeignKey(Page)
@property
def urlpatterns(self):
urlpatterns = self.feed_patterns(r'^', 'get_all_entries', 'index_page', 'index')
urlpatterns += self.feed_patterns(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})', 'get_entries_by_ymd', 'entry_archive_page', 'entries_by_day')
return urlpatterns
def get_entries_by_ymd(request, year, month, day, extra_context=None):
entries = Blog.entries.all()
# filter entries based on the year, month, and day.
return entries, extra_context
See also
By default, returns the object stored in the attribute named by object_attr. This can be overridden for subclasses that publish different data for different URL parameters. It is part of the django.contrib.syndication.views.Feed API.
Returns a view function that renders a list of items as a feed.
Parameters: |
|
---|---|
Returns: | A view function that renders a list of items as a feed. |
Parameters: |
|
---|---|
Returns: | A view function that renders a list of items as an HttpResponse. |
Hook for handling any extra processing of items based on an HttpRequest, such as pagination or searching. This method is expected to return a list of items and a dictionary to be added to the page context.
If feed_type is not None, returns the corresponding class from the registry or raises HttpNotAcceptable.
Otherwise, intelligently chooses a feed type for a given request. Tries to return feed_type, but if the Accept header does not include that mimetype, tries to return the best match from the feed types that are offered by the FeedView. If none of the offered feed types are accepted by the HttpRequest, raises HttpNotAcceptable.
If mimeparse is installed, it will be used to select the best matching accepted format; otherwise, the first available format that is accepted will be selected.
Returns an unpopulated django.utils.feedgenerator.DefaultFeed object for this object.
Parameters: |
|
---|---|
Returns: | An instance of the feed class registered as feed_type, falling back to feed_type if feed_type is None. |
Populates a django.utils.feedgenerator.DefaultFeed instance as is returned by get_feed() with the passed-in items.
Returns an extra keyword arguments dictionary that is used when initializing the feed generator.
Returns an extra keyword arguments dictionary that is used with the add_item call of the feed generator.
This will be raised in FeedView.get_feed_type() if an Http-Accept header will not accept any of the feed content types that are available.
Middleware to catch HttpNotAcceptable and return an HttpResponse with a 406 response code. See RFC 2616.