django-debug-toolbar 与 django-cms 和 Django 1.3

发布于 2024-11-01 06:06:18 字数 331 浏览 2 评论 0原文

尝试一起使用 django-debug-toolbar 和 django-cms 时,我不断遇到错误。

“MpttMeta 没有属性 'class'”

我感觉这与与 Django CMS 捆绑在一起的 Mptt 应用程序有关,但我不确定,而且我在一些项目中看到过这种情况但我很惊讶我在谷歌中找不到错误消息的直接点击,所以我想我应该在这里发布。

我尝试过使用最新发布版本的调试工具栏、开发分支以及 dcramer 的分支,但没有任何区别。我使用的是 Django 1.3 和 Django CMS 2.1.3。

有什么想法吗?

谢谢!

I keep hitting an error when trying to use django-debug-toolbar and django-cms together.

"MpttMeta has no attribute 'class'"

I have a feeling it's something to do with the Mptt app bundled with Django CMS, but I'm not sure, and I've seen this on a few projects but I'm surprised I can't find a direct hit for the error message in Google so I thought I'd post here.

I've tried using latest released version of debug toolbar, also the develop branch, and also dcramer's fork, but it's making no difference. I'm on Django 1.3 and Django CMS 2.1.3.

Any ideas?

Thanks!

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

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

发布评论

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

评论(4

ら栖息 2024-11-08 06:06:18

问题是 django-debug-toolbar 期望 MpttMeta 类需要是一个“新样式”类,这是一个相当简单的补丁(django-cms/publisher/mptt_support.py 中的第 33 行)。更改:

class MpttMeta:

class MpttMeta(object):

Django-CMS 2.1.3 中,他们仍然有自己的猴子补丁 mptt 与 Django-CMS 捆绑在一起。在下一个版本的Django-CMS中,将不再捆绑自己的mptt,而是依赖独立开发的包。

The problem is that django-debug-toolbar expects the MpttMeta class needs to be a 'new style' class, which is a fairly straightforward patch (line 33 in django-cms/publisher/mptt_support.py). Change:

class MpttMeta:

to

class MpttMeta(object):

In Django-CMS 2.1.3, they still have their own monkey-patched mptt bundled with Django-CMS. In the next release of Django-CMS will no longer bundle its own mptt and will instead rely on the independently developed package.

小兔几 2024-11-08 06:06:18

这可能是与 Django 1.3 相关的任何问题。

Django CMS 2.1.3 仅支持 1.2.X 分支: http ://docs.django-cms.org/en/2.1.3/getting_started/installation.html#requirements

Jonas Obrist,Django CMS 开发人员说"可能是以下版本的次要版本
2.1将添加官方1.3支持”

It could be any problem related to Django 1.3.

Django CMS 2.1.3 supports only 1.2.X branch: http://docs.django-cms.org/en/2.1.3/getting_started/installation.html#requirements

Jonas Obrist, Django CMS dev says "Maybe a minor version of
2.1 will add official 1.3 support"

樱&纷飞 2024-11-08 06:06:18

或者你可以把它放在你的.... urls.py 中。不在 settings.py 中,因为项目将无法启动。

from publisher.mptt_support import MpttMeta
if not hasattr(MpttMeta, '__class__'):
    MpttMeta.__class__ = type

Or you can put this in yours .... urls.py for example. Not in settings.py because project will not start.

from publisher.mptt_support import MpttMeta
if not hasattr(MpttMeta, '__class__'):
    MpttMeta.__class__ = type
阿楠 2024-11-08 06:06:18
Caught AttributeError while rendering: class MpttMeta has no attribute '__class__'

我相信这与 MPTTMeta 类加载到元类 (MPTTModelBase) 的方式有关,使其没有 class 属性。

Monkeypatch 修复是将有问题的语句包装在 django-debug-toolbar 中,如下所示:

try:
    text = "method %s on %s object" % (receiver.__name__, receiver.im_self.__class__.__name__)
except:
    text = "method %s on %s object" % (receiver.__name__, type(receiver.im_self).__name__)

这会稍微改变输出,显然

method finish_mptt_class on classobj object

不是永久修复,但它可以让 debug-toolbar + django-cms 正常工作。

Caught AttributeError while rendering: class MpttMeta has no attribute '__class__'

I believe this had to do with the way the MPTTMeta class is loaded into the metaclass (MPTTModelBase) making it not have a class attribute.

A monkeypatch fix is to wrap the offending statement in django-debug-toolbar like so:

try:
    text = "method %s on %s object" % (receiver.__name__, receiver.im_self.__class__.__name__)
except:
    text = "method %s on %s object" % (receiver.__name__, type(receiver.im_self).__name__)

This changes the output slightly to become

method finish_mptt_class on classobj object

Clearly not a permanent fix, but it gets you the debug-toolbar + django-cms working.

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