views:

608

answers:

4

I followed along this tutorial for django's RSS and ATOM feeds and I got it to work.

However the test development server keeps making the browser download the feeds as a file instead of the browser detecting it as an xml document.

My experience with HTTP tells me that there is a missing mime type in the Content-Type header.

How do I specify that in django?

+1  A: 

When you create an HTTPReponse object you can specify its content-type:

HttpResponse(content_type='application/xml')

Or whatever the content type actually is.

See http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.__init__

dbb
As I mentioned above, you don't use an HttpResponse nor rendr_to_response call with syndication in Django.
Net Citizen
+2  A: 

Are you using the available view for rss? This is what I have in my urls.py - and I am not setting anything about mimetypes:

urlpatterns += patterns('',
    (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': published_feeds}, 'view_name')`,
)

where published_feeds is something like

class LatestNewsFeed(Feed):
    def get_object(self, bits):
      pass

    def title(self, obj):
      return "Feed title"

    def link(self, obj):
      if not obj:
        return FeedDoesNotExist
      return slugify(obj[0])

    def description(self, obj):
      return "Feed description"

    def items(self, obj):
      return obj[1]

published_feeds = {'mlist': LatestNewsFeed}
Roberto Liffredo
A: 

I guess the problem was with the Camino browser on OS X, not with the HTTP header and mime type.

When I tried on Safari, it worked.

Net Citizen
+2  A: 

There is a comment in the Everyblock source code about this.

They define a class that replaces the mime type of the standard Django feed like so:

# RSS feeds powered by Django's syndication framework use MIME type
# 'application/rss+xml'. That's unacceptable to us, because that MIME type
# prompts users to download the feed in some browsers, which is confusing.
# Here, we set the MIME type so that it doesn't do that prompt.
class CorrectMimeTypeFeed(Rss201rev2Feed):
    mime_type = 'application/xml'

# This is a django.contrib.syndication.feeds.Feed subclass whose feed_type
# is set to our preferred MIME type.
class EbpubFeed(Feed):
    feed_type = CorrectMimeTypeFeed
David