Django

Code

root/django/trunk/django/contrib/syndication/views.py

Revision 5654, 0.7 kB (checked in by adrian, 1 year ago)

Improved syndication feed framework to use RequestSite? if the sites framework is not installed -- i.e., the sites framework is no longer required to use the syndication feed framework. This is backwards incompatible if anybody has subclassed Feed and overridden init(), because the second parameter is now expected to be an HttpRequest object instead of request.path

  • Property svn:eol-style set to native
Line 
1 from django.contrib.syndication import feeds
2 from django.http import HttpResponse, Http404
3
4 def feed(request, url, feed_dict=None):
5     if not feed_dict:
6         raise Http404, "No feeds are registered."
7
8     try:
9         slug, param = url.split('/', 1)
10     except ValueError:
11         slug, param = url, ''
12
13     try:
14         f = feed_dict[slug]
15     except KeyError:
16         raise Http404, "Slug %r isn't registered." % slug
17
18     try:
19         feedgen = f(slug, request).get_feed(param)
20     except feeds.FeedDoesNotExist:
21         raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug
22
23     response = HttpResponse(mimetype=feedgen.mime_type)
24     feedgen.write(response, 'utf-8')
25     return response
Note: See TracBrowser for help on using the browser.