0

我尝试使用(of ) 在django.contrib.syndication.viewsCache-Control中设置HTTP 标头,但徒劳无功:cache_control()django.views.decorators.cache

from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
import lxml.html
import requests

class TestFeed(Feed):
    feed_type = Atom1Feed
    language = 'zh-Hant-TW'
    link = 'https://www.example.com/feed'
    title = 'Sample feed'

    def items(self):
        s = requests.Session()
        r = s.get(self.link)
        body = lxml.html.fromstring(r.text)
        items = body.cssselect('.item a')

        return items

    def item_description(self, item):
        img = item.cssselect('img')[0]
        img.set('src', img.get('data-src'))
        content = lxml.etree.tostring(item, encoding='unicode')

        return content

    def item_link(self, item):
        link = item.get('href')

        return link

    def item_title(self, item):
        title = item.get('title')

        return title

在跟踪django.contrib.syndication.views 的源代码之后,似乎不太可能使用装饰器将 HTTP 标头添加到 HTTP 响应对象中。

有什么解决方法可以做到这一点吗?

4

0 回答 0