Django FeinCMS 和页面扩展问题
我想创建这个简单的页面扩展:
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'
I'm experimenting with Page extensions and FeinCMS 1.2.1.
I'd like to create this simple page extension:
from django.db import models
def register(cls, admin_cls):
cls.add_to_class(models.TextField())
but I keep getting this error:
AttributeError: 'module' object has no attribute 'TextField'
The package containing the extension is called dev.extensions
and the module categories
, I have added it to the Python path and the extension is registered with Page.register_extensions('dev.extensions.categories')
.
I'm wondering what I'm doing wrong, please help.
The complete stacktrace follows.
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的注册函数运行之前,也许模型会被重新分配给另一个模块?
尝试将您的代码更改为:
Maybe models is getting reassigned somewhere to another module before your register function gets run?
Try changing your code to this: