私はckeditorを使って自分の設定にカスタムウィジェットを定義します。あるページではこのカスタムテンプレートを使用しようとしましたが、カスタムウィジェットは表示されません。フルウィジェットで表示されます。django-ckeditorは私のカスタムウィジェットの代わりにフルウィジェットをレンダリングします
この場合、私はajaxリクエストから1つのフォームを使用します。
マイモデル:
class Comment(models.Model):
content = models.CharField(max_length=settings.COMMENT_TEXT_LIMIT if hasattr(settings, "COMMENT_TEXT_LIMIT") else 10000)
マイ形式:
class CreateCommentForm(IdeiaForm):
content = forms.CharField(
max_length=settings.COMMENT_TEXT_LIMIT if hasattr(settings, "COMMENT_TEXT_LIMIT") else 10000,
required=True,
widget=forms.Textarea(attrs={'data-config': json_encode(getattr(settings, 'CKEDITOR_CONFIGS', None)['comment'])}))
と私のHTMLファイル:
<textarea id="text_area_content" name="content" class="form-control" placeholder="Deixe seu comentário" data-url-login="{% url 'account:is_logged' %}" data-trigger="login" data-token="{{ csrf_token }}"></textarea>
私のsettings.py:
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'Basic',
},
'comment': {
'toolbar': 'Custom',
'toolbar_Custom': [
['Bold', 'Italic'],
['CodeSnippet'],
],
'entities': False,
'extraPlugins': ','.join([
'autolink', 'dialog',
'codesnippet','autogrow','placeholder',
]),
},
}
'' CKEDITOR_CONFIGS''が定義されていない場合、 'json_encode(getattr(settings、 'CKEDITOR_CONFIGS'、None)['comment']'はKeyErrorを送出します。 これはすべきです – jaap3
「AJAXリクエストから来たフォーム」はおそらくあなたのビューを添付していると思いますか?いいえ、おそらく 'json_encode(getattr(settings、 'CKEDITOR_CONFIGS'、{}) – tutuDajuju