将 TinyMCE 集成到 Django
Integrating TinyMCE to Django
所以我一直在尝试在我的 django 项目上使用 tinymce,但我不断收到:ImportError: cannot import name 'TinyMCE' from 'tinymce' 和 Cannot find reference TinyMCE in init.py
网上很少有文章讨论将 tinymce 与 django admin 集成,但我正在尝试将其与我的 django 表单集成。
pip installed django-tinymce
settings.py:
INSTALLED_APPS = [ 'tinymce',]
urls.py:
path('tinymce/', include('tinymce.urls')),
models.py:
from tinymce.models import HTMLField
container_description = HTMLField()
forms.py
from tinymce import TinyMCE
class TinyMCEWidget(TinyMCE):
def use_required_attribute(self, *args):
return False
class ContainerForm(forms.ModelForm):
container_serial_number = forms.CharField(widget=forms.TextInput(attrs=
{'placeholder': 'Enter serial number'}))
container_description = forms.CharField(required=False,
widget=TinyMCEWidget(attrs={'placeholder': 'Enter
description'}), max_length=100)
按照在线说明进行设置,但我仍然遇到 ImportError。我还应该做些什么来设置 TinyMCE?
您需要更换:
from tinymce import TinyMCE
与:
from tinymce.widgets import TinyMCE
根据 documentation 中的示例。
所以我一直在尝试在我的 django 项目上使用 tinymce,但我不断收到:ImportError: cannot import name 'TinyMCE' from 'tinymce' 和 Cannot find reference TinyMCE in init.py
网上很少有文章讨论将 tinymce 与 django admin 集成,但我正在尝试将其与我的 django 表单集成。
pip installed django-tinymce
settings.py:
INSTALLED_APPS = [ 'tinymce',]
urls.py:
path('tinymce/', include('tinymce.urls')),
models.py:
from tinymce.models import HTMLField
container_description = HTMLField()
forms.py
from tinymce import TinyMCE
class TinyMCEWidget(TinyMCE):
def use_required_attribute(self, *args):
return False
class ContainerForm(forms.ModelForm):
container_serial_number = forms.CharField(widget=forms.TextInput(attrs=
{'placeholder': 'Enter serial number'}))
container_description = forms.CharField(required=False,
widget=TinyMCEWidget(attrs={'placeholder': 'Enter
description'}), max_length=100)
按照在线说明进行设置,但我仍然遇到 ImportError。我还应该做些什么来设置 TinyMCE?
您需要更换:
from tinymce import TinyMCE
与:
from tinymce.widgets import TinyMCE
根据 documentation 中的示例。