Created
October 19, 2009 02:48
-
-
Save hdknr/213046 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# django/contrib/syndication/views.py | |
# | |
from django.contrib.syndication import feeds | |
from django.http import HttpResponse, Http404 | |
def feed(request, url, feed_dict=None): | |
if not feed_dict: | |
raise Http404, "No feeds are registered." | |
try: | |
slug, param = url.split('/', 1) | |
except ValueError: | |
slug, param = url, '' | |
try: | |
f = feed_dict[slug] | |
except KeyError: | |
raise Http404, "Slug %r isn't registered." % slug | |
try: | |
feedgen = f(slug, request).get_feed(param) | |
except feeds.FeedDoesNotExist: | |
raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug | |
response = HttpResponse(mimetype=feedgen.mime_type) | |
feedgen.write(response, 'utf-8') | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment