I define some custom widgets in my settings for user with ckeditor. In one page I try use this custom template and it dont show me a custom widget, it is displayed with full widget.
In this case, I use one form that cames from ajax request.
My model:
class Comment(models.Model):
content = models.CharField(max_length=settings.COMMENT_TEXT_LIMIT if hasattr(settings, "COMMENT_TEXT_LIMIT") else 10000)
My form:
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'])}))
and my HTML file:
<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>
My settings.py:
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'Basic',
},
'comment': {
'toolbar': 'Custom',
'toolbar_Custom': [
['Bold', 'Italic'],
['CodeSnippet'],
],
'entities': False,
'extraPlugins': ','.join([
'autolink', 'dialog',
'codesnippet','autogrow','placeholder',
]),
},
}
I'm assuming the HTML file you're speaking of is a Django template.
It seems you are not actually using the textarea you've defined in the form. So the custom data-config
attribute is not used.
If you have access to the form in the template you should use {{ form.text_area_content }}
to render the field you've defined.
If I understand what you're trying to achieve, the documentation mentions you can reference your custom CKEditor settings either in RichTextField
or eg when using a CKEditorWidget
:
from ckeditor.widgets import CKEditorWidget
class CreateCommentForm(IdeiaForm):
content = forms.CharField(
max_length=getattr(settings, "COMMENT_TEXT_LIMIT", 10000),
required=True,widget=CKEditorWidget(config_name='comment')
)
You then have to make sure you render the form using template tags (as in @jaap3's answer), updating the docs example, and assuming you're passing the form to the view as form = CreateCommentForm()
:
<form>
{{ form.media }}
{{ form.as_p }}
<input type="submit"/>
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.