문제

나는 따라 갔다 이 튜토리얼 Django의 RSS와 Atom 피드의 경우 작동하게되었습니다.

그러나 Test Development Server는 브라우저가 브라우저 대신 파일로 브라우저를 XML 문서로 감지하는 대신 파일로 계속 다운로드합니다.

HTTP에 대한 나의 경험에 따르면 컨텐츠 유형 헤더에는 누락 된 마임 유형이 있다고합니다.

django에서 어떻게 지정합니까?

도움이 되었습니까?

해결책 4

문제는 HTTP 헤더 및 MIME 유형이 아닌 OS X의 Camino 브라우저에 문제가 있다고 생각합니다.

Safari를 시도했을 때 효과가있었습니다.

다른 팁

이에 대한 EveryBlock 소스 코드에는 주석이 있습니다.

그들은 표준 Django 피드의 마임 유형을 대체하는 클래스를 정의합니다.

# 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

RSS에 사용 가능한보기를 사용하고 있습니까? 이것이 제가 urls.py에있는 것입니다. 그리고 나는 mimetypes에 대해 아무것도 설정하지 않습니다.

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

Published_feeds는 어디에 있습니다

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}

httpreponse 객체를 만들 때 컨텐츠 유형을 지정할 수 있습니다.

HttpResponse(content_type='application/xml')

또는 콘텐츠 유형이 실제로 무엇이든.

보다 http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.httpresponse.__init__

나는 여전히 9 년 후 Firefox와 Django 2.1과 함께이 문제를 겪었습니다.

위의 솔루션은 그것을 자르지 않았으므로 다음을 사용했습니다.

class XMLFeed(Feed):
    def get_feed(self, obj, request):
        feedgen = super().get_feed(obj, request)
        feedgen.content_type = 'application/xml; charset=utf-8'
        return feedgen

대신이 수업을 사용합니다 Feed 마임 유형을 원하는대로 'Application/XML'으로 설정합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top