正确的Django RSS联合框架时区

时间:2014-01-22 21:41:09

标签: django timezone

我按照documentation

在我的django项目上获得了RSS Feed设置

但看起来<lastBuildDate>Thu, 23 Jan 2014 10:23:31 -0000</lastBuildDate>上的时间戳没有给出正确的时间偏移,这应该是+13小时。

我的设置是:

TIME_ZONE = 'Pacific/Auckland'

LANGUAGE_CODE = 'en-nz'

USE_I18N = True

USE_L10N = True

USE_TZ = True

1 个答案:

答案 0 :(得分:0)

看起来我需要在类中定义item_pubdate函数:

from articles.models import Story
from django.contrib.syndication.views import Feed
from django.contrib.sites.models import Site

current_site = Site.objects.get_current()
.
class LatestStoriesFeed(Feed):
    title = 'Latest stories'
    link = "/" 

    def items(self):
        return Story.active_objects.filter(sites__in=[current_site])[:10]
....
    def item_title(self, item):
        return item.title

    def item_descrpition(self, item):
        return item.introtext

    def item_link(self, item):
        return item.get_absolute_url()

    def item_pubdate(self, item):
        return item.publish_date