summaryrefslogtreecommitdiff
path: root/django/contrib/syndication/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/syndication/views.py')
-rw-r--r--django/contrib/syndication/views.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
new file mode 100644
index 0000000000..3236f9dfab
--- /dev/null
+++ b/django/contrib/syndication/views.py
@@ -0,0 +1,26 @@
+from django.contrib.syndication import feeds
+from django.core.exceptions import Http404
+from django.utils.httpwrappers import HttpResponse
+
+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).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='application/xml')
+ feedgen.write(response, 'utf-8')
+ return response