我正在处理Python/Django/Wagtail项目,我有一些api来返回一些分页的文章。事情是这样的:
以网址表示:
url(r'^morearticles/', views.get_live_articles),意见:
def get_live_articles(request):
context = {'articles': getLiveArticles(request) }
return render(request, 'app/components/articles-live.html', context, content_type="text/html; charset=utf-8")getLiveArticles函数如下所示:
def getLiveArticles(request):
# Articles
a = get_articles() #this is getting the articles correctly
p = Paginator(a, 4)
page_n = request.GET.get('page')
try:
articles = p.page(page_n)
except Exception, e:
articles = []
return articles然而,在访问api端点时,我得到了以下信息:
Traceback (most recent call last):
File "/Users/john/.virtualenvs/upgrade/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Users/john/.virtualenvs/upgrade/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/Users/john/.virtualenvs/upgrade/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/john/.virtualenvs/upgrade/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/john/app/app/views.py", line 90, in get_live_articles
context = {'articles': getLiveArticles(request) }
File "/Users/john/.virtualenvs/upgrade/lib/python2.7/site-packages/cache_utils/decorators.py", line 48, in wrapper
cache.set(key, value, timeout, **backend_kwargs)
File "/Users/john/.virtualenvs/upgrade/lib/python2.7/site-packages/django/core/cache/backends/locmem.py", line 75, in set
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
PicklingError: Can't pickle <class 'wagtail.wagtailcore.blocks.base.RichTextBlockMeta'>: attribute lookup wagtail.wagtailcore.blocks.base.RichTextBlockMeta failed我以前遇到过腌制错误,但从来不太明白它是怎么回事。知道是什么导致了这一切吗?
如果我需要提供更多的信息,请告诉我。调试后,我认为问题必须包含在这些代码块中,但我可能错了。
编辑:最近,对象的一个字段被转换为包含主要内容的StreamField对象。那可能有什么关系吗?
发布于 2018-06-05 18:23:14
我认为这是与缓存相关的(最近也发生了同样的问题),其中有些对象不能用于缓存,而且正如您已经确认的那样,您正在使用缓存。因此,禁用缓存将解决问题。
建议使用与泡菜兼容的对象类型。另一方面,在Python文档中有一些如何实现/自定义泡菜/去泡菜逻辑的指导方针。
https://stackoverflow.com/questions/50706311
复制相似问题