gpt4 book ai didi

python - Django FeinCMS 和页面扩展问题

转载 作者:行者123 更新时间:2023-11-30 23:54:13 25 4
gpt4 key购买 nike

我正在尝试 Page extensionsFeinCMS 1.2.1.

我想创建这个简单的页面扩展:

from django.db import models

def register(cls, admin_cls):
cls.add_to_class(models.TextField())

但我不断收到此错误:

AttributeError: 'module' object has no attribute 'TextField'

包含扩展的包称为dev.extensions和模块categories,我已将其添加到Python路径中,并且扩展已注册到Page .register_extensions('dev.extensions.categories').

我想知道我做错了什么,请帮忙。

完整的堆栈跟踪如下。

c:\sandbox\projects\feindev>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_manager(settings)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 436, in execute_m
anager
setup_environ(settings_mod)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 419, in setup_env
iron
project_module = import_module(project_name)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "c:\sandbox\projects\feindev\..\fein
dev\__init__.py", line 52, in <module>
Page.register_extensions('dev.extensions.types')
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\models.py", line 270, in register_extensions
cls.register_extension(fn)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\module\page\models.py", line 564, in register_exten
sion
register_fn(cls, PageAdmin)
File "c:\sandbox\projects\feindev\dev\ext
ensions\types\__init__.py", line 4, in register
cls.add_to_class(models.TextField())
AttributeError: 'module' object has no attribute 'TextField'

最佳答案

也许在你的注册函数运行之前模型被重新分配给另一个模块?

尝试将代码更改为:

from django.db import models as django_models

def register(cls, admin_cls):
cls.add_to_class('field_name_here', django_models.TextField())

关于python - Django FeinCMS 和页面扩展问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5286182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com