gpt4 book ai didi

python - 属性错误 : module 'django.db.models' has no attribute 'RichTextField'

转载 作者:行者123 更新时间:2023-12-05 02:08:04 24 4
gpt4 key购买 nike

我是 wagtail 的新手,正在学习官方教程和 youtube 教程(yt 教程跳过了安装 libjpeg 和 zlib 的说明,但当我尝试安装时,它说 Pillow 包含它们);在windows10上运行,使用最新的python,最新的wagtail,最新的django;停留在第一点,在运行 makemigrations 或 migrate 或 runserver 时仍然遇到同样的问题:

File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\home\models.py", line 14, in 
HomePage
banner_subtitle = models.RichTextField(features=["bold", "italic"])
AttributeError: module 'django.db.models' has no attribute 'RichTextField'

这是我的模型.py:

    from django.db import models

from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel

class HomePage(Page):
"""Homepage model."""
body = RichTextField(blank=True)
templates = "templates/home/home_page.html"
max_count = 1

banner_title = models.CharField('Body', blank=True)
banner_subtitle = models.RichTextField(features=["bold", "italic"])
banner_image = models.ForeignKey(features=
"wagtailImages.Image",
null=False,
blank=False,
on_delete=models.SET_NULL,
related_name="+"
)
banner_cta = models.ForeignKey(
"wagtailcore.Page",
)

content_panels = Page.content_panels + [
FieldPanel("banner_title"),

]
class Meta:
verbose_name = "HomePage"
verbose_name_plural = "HomePages"

这是完整的回溯:

Traceback (most recent call last):
File ".\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\venv_bloggyblog\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\venv_bloggyblog\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\venv_bloggyblog\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\venv_bloggyblog\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\venv_bloggyblog\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Program Files\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\home\models.py", line 7, in <module>
class HomePage(Page):
File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\home\models.py", line 14, in
HomePage
banner_subtitle = models.RichTextField(features=["bold", "italic"])
AttributeError: module 'django.db.models' has no attribute 'RichTextField'

下面是我运行 wagtail updatemodulepaths 时发生的情况:

Traceback (most recent call last):
File "C:\Program Files\Python38\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\TalkyWalky\Desktop\Workspace\bloggyblog\venv_bloggyblog\Scripts\wagtail.exe\__main__.py", line 7, in <module>
File "c:\users\talkywalky\desktop\workspace\bloggyblog\venv_bloggyblog\lib\site-packages\wagtail\bin\wagtail.py", line 297, in main
command.execute(sys.argv)
File "c:\users\talkywalky\desktop\workspace\bloggyblog\venv_bloggyblog\lib\site-packages\wagtail\bin\wagtail.py", line 52, in execute
self.run(**options_dict)
File "c:\users\talkywalky\desktop\workspace\bloggyblog\venv_bloggyblog\lib\site-packages\wagtail\bin\wagtail.py", line 171, in run
change_count = self._rewrite_file(path)
File "c:\users\talkywalky\desktop\workspace\bloggyblog\venv_bloggyblog\lib\site-packages\wagtail\bin\wagtail.py", line 236, in _rewrite_file
for original_line in f:
File "C:\Program Files\Python38\lib\fileinput.py", line 248, in __next__
line = self._readline()
File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 641: character
maps to <undefined>

最佳答案

你不应该写 <s>models.</s>RichTextField ,因为实际上,django.db.models 中不存在此类模块。你应该简单地使用 RichTextField ,因为你导入了那个:

from django.db import models

from wagtail.core.models import Page
from wagtail.core.fields import <b>RichTextField</b>
from wagtail.admin.edit_handlers import FieldPanel

class HomePage(Page):
"""Homepage model."""
body = RichTextField(blank=True)
templates = "templates/home/home_page.html"
max_count = 1

banner_title = models.CharField('Body', blank=True)
# no <s>models.</s>
banner_subtitle = <b>RichTextField(</b>features=["bold", "italic"]<b>)</b>
banner_image = models.ForeignKey(features=
"wagtailImages.Image",
null=False,
blank=False,
on_delete=models.SET_NULL,
related_name="+"
)
banner_cta = models.ForeignKey(
"wagtailcore.Page",
)

content_panels = Page.content_panels + [
FieldPanel("banner_title"),

]
class Meta:
verbose_name = "HomePage"
verbose_name_plural = "HomePages"

关于python - 属性错误 : module 'django.db.models' has no attribute 'RichTextField' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61258929/

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