I'm not too well versed in this whole web application development
world yet, so maybe this is a dumb question...
When I click on a link to an RSS feed on a Wordpress powered blog, for
example, Firefox quickly displays the xml with fancy highlighting and
indentation and stuff. When I click on a link to an RSS feed on my
Django powered website, Firefox has no idea what to do with it and
prompts me with a dialog. I noticed that RSS feeds from
djangoproject.com and LjWord.com have the same issue. This is a bit
of a bummer because the quick nicely-formatted display that Firefox
does would make it very easy to verify that the feeds I'm creating
look sane. Does anyone know how to fix this?
Thanks,
Bryan
Displays nicely:
http://www.blueskyonmars.com/?feed=rss&cat=19
Doesn't:
http://www.djangoproject.com/rss/weblog/
Bryan
Apparently firefox doesn't know what to do with rss version 2.0. Change it
to:
<rss version="0.92">
which is what is in the wordpress feed and it displays the way you want it (on
my machine, anyway).
Eric.
My feed displays nicely too: http://lazutkin.com/blog/rss201.xml. I
generate it with Django using RSS 2.0 spec courtesy of
django.utils.feedgenerator.Rss201rev2Feed. I suspect the difference is
due to different MIME type of these feeds --- I use 'application/xml',
which I believe is the correct one.
Thanks,
Eugene
application/rss+xml for RSS
application/atom+xml for Atom
Browsers should prompt to download on these types, or if you've
configured a feed reader to handle them defer to the feed reader
instead.
--
"May the forces of evil become confused on the way to your house."
-- George Carlin
So are those the MIME types that django is returning for rss feeds (in
other words, how do I find out what MIME type django is using for
these)? In that case and from what you are saying, firefox is doing
the correct thing in asking me where to save the file instead of just
displaying it?
Thanks,
Bryan
Yes and yes.
To find out the MIME-type Django is using, either look at the
Content-Type header it returns, or look at the feed-generating code,
which generates HttpResponses with those MIME-types.
http://127.0.0.1:8000/feeds/nouvelles/
GET /feeds/nouvelles/ HTTP/1.1
Host: 127.0.0.1:8000
User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.8.0.4)
Gecko/20060508 Firefox/1.5.0.4
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,fr;q=0.8,fr-fr;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://127.0.0.1:8000/compte/coulix/
Cookie: sessionid=be7df207bc4edba9e0ca30f189d295aa;
__utma=96992031.993593871.1150179699.1150193251.1150210787.4;
__utmc=96992031;
__utmz=96992031.1150179699.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)
HTTP/1.x 200 OK
Date: Wed Jun 14 00:15:52 2006
Server: WSGIServer/0.1 Python/2.4.2
Vary: Cookie
Content-Type: application/rss+xml
Answer to my own question that I found by digging through the django
code (which is much easier than I had anticipated!). The MIME type
for each feed is set in the feedgenerator.py:
http://code.djangoproject.com/browser/django/trunk/django/utils/feedgenerator.py
And it sets them just as James indicates. That probably explains why
firefox isn't displaying them like I wish.
As for Eugene's example, firefox does display it, and confirms that
the content-type header was application/xml. That isn't what django
sets for Rss201rev2Feeds. Maybe, Eugene, you are overriding that
somewhere in your code?
Thanks,
Bryan
This is because browsers are NOT supposed to display feeds as XML documents.
Think of it like PDF -- instead of displaying the raw source text of
the PDF, the browser loads Adobe Acrobat. With a feed, instead of
displaying the raw XML the browser is supposed to hand off to a feed
reader. If you haven't told your browser or operating system what
program you use to read feeds, the default behavior, which is what
most people will see because they haven't done this configuration, is
to prompt you to download the document.
Firefox is doing the right thing. Displaying raw XML to an end user is
not a good thing, and is more likely to make the user think they've
broken your site or done something wrong than anything else.
Yes, I override it. I remember having problems with some news
integrators with other MIME types. Like James said it should be
"application/rss+xml for RSS, application/atom+xml for Atom", but not
everybody conforms to the standard --- so I decided to declare it as XML.
Thanks,
Eugene