django feeds 的发布日期错误

发布于 2024-10-05 10:34:41 字数 837 浏览 0 评论 0原文

我有以下问题。

项目的 django-piston api 的 handlers.py:

....
# "need" to set this for datetime.strftime()
locale.setlocale(locale.LC_TIME,'de_AT.UTF-8')

class ItemOverviewHandler(BaseHandler):
    ...
    @classmethod
    def date(self, item):
        # because of the setlocale() call the datestring is in german
        # that's good
        return item.somedatefield.date.strftime("%d. %B %Y")
 ...

现在看来这会影响项目的提要(使用 django.contrib.syndicate 创建):(

def item_pubdate(self, item):
    return item.pub_date #datetime field
# the rss look's like this
# that's not good
<pubDate>Die, 17 Aug 2010 14:00:00 +0200</pubDate>

这是一个 rfc 一致日期,但在德语中 Die == Dienstag == Tuesday),因此这是无效的。

所以我需要活塞 API 响应为德语(已完成)。但提要的 pubDate 必须是英文(不知道如何实现这一点)。

有什么建议吗?

I have following problem.

handlers.py of project's django-piston api:

....
# "need" to set this for datetime.strftime()
locale.setlocale(locale.LC_TIME,'de_AT.UTF-8')

class ItemOverviewHandler(BaseHandler):
    ...
    @classmethod
    def date(self, item):
        # because of the setlocale() call the datestring is in german
        # that's good
        return item.somedatefield.date.strftime("%d. %B %Y")
 ...

now it seems like this effects the project's feeds (created with django.contrib.syndication):

def item_pubdate(self, item):
    return item.pub_date #datetime field
# the rss look's like this
# that's not good
<pubDate>Die, 17 Aug 2010 14:00:00 +0200</pubDate>

(this is an rfc conform date, BUT in german Die == Dienstag == Tuesday), thus it's invalid.

So I need the piston api response to be in german (done). but pubDate of the feed has to be in english (have no idea how to accomplish this).

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷迭香的记忆 2024-10-12 10:34:41

这成功了。但我仍然愿意接受其他建议:)

class ItemOverviewHandler(BaseHandler):
    ...
    @classmethod
    def date(self, item):
        locale.setlocale(locale.LC_TIME,'de_AT.UTF-8')
        date_string = item.somedatefield.date.strftime("%d. %B %Y")
        locale.setlocale(locale.LC_TIME,'')
        return date_string

this did the trick. but im still open for other suggestions :)

class ItemOverviewHandler(BaseHandler):
    ...
    @classmethod
    def date(self, item):
        locale.setlocale(locale.LC_TIME,'de_AT.UTF-8')
        date_string = item.somedatefield.date.strftime("%d. %B %Y")
        locale.setlocale(locale.LC_TIME,'')
        return date_string
梨涡 2024-10-12 10:34:41

您可以使用 Babel 国际化模块。请在此处查找用于格式化日期时间的 format_date 函数特定区域设置。

You could use the Babel internationalization module. Look here for the format_date function that formats datetime with a specific locale.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文