cache_page与基于类的视图 [英] cache_page with Class Based Views

查看:160
本文介绍了cache_page与基于类的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用基于类的视图(TemplateView)执行cache_page,我无法执行。我遵循这里的说明:

I'm trying to do cache_page with class based views (TemplateView) and i'm not able to. I followed instructions here:

Django - 基于类的视图的URL缓存失败

以及这里:

https://github.com/msgre/hazard/blob /master/hazard/urls.py

但是我收到这个错误:

cache_page has a single mandatory positional argument: timeout

我读取代码cache_page,它具有以下内容:

I read the code for cache_page and it has the following:

if len(args) != 1 or callable(args[0]):
    raise TypeError("cache_page has a single mandatory positional argument: timeout")
cache_timeout = args[0]

这意味着它不允许多于1个参数。有没有其他方法来获取cache_page工作?我一直在挖这个东西...

which means it wont allow more than 1 argument. Is there any other way to get cache_page to work?? I have been digging into this for sometime...

似乎以前的解决方案不再工作

It seems like the previous solutions wont work any longer

推荐答案

根据缓存文档文档,缓存CBV的正确方法是

According to the caching docs docs, the correct way to cache a CBV is

url(r'^my_url/?$', cache_page(60*60)(MyView.as_view())),

请注意你链接的答案是过时的。旧的使用装饰器的方法已被删除(更改集)。

Note that the answer you linked to is out of date. The old way of using the decorator has been removed (changeset).

这篇关于cache_page与基于类的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆