I made my own ckeditor structure through this link and displayed it in my template using vanilla js and CDN.
Everything works fine and I can edit my texts very easily, but I don’t know how to send the information filled through this box to the view after pressing the submit button and save it in the content field through the ModelForm in database.
template:
<link rel="stylesheet" href="{% static 'ckeditor/style.css' %}">
<link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/43.1.0/ckeditor5.css">
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
...
<div class="main-container">
<div class="editor-container editor-container_classic-editor editor-container_include-block-toolbar" id="editor-container">
<div class="editor-container__editor prose">
<div id="editor"></div>
</div>
</div>
</div>
<button type="submit">Submit</button>
</form>
<script type="importmap">
{
"imports": {
"ckeditor5": "https://cdn.ckeditor.com/ckeditor5/43.1.0/ckeditor5.js",
"ckeditor5/": "https://cdn.ckeditor.com/ckeditor5/43.1.0/"
}
}
</script>
<script type="module" src="{% static 'ckeditor/main.js' %}"></script>
I used the Feature-rich Editor
option, so the content may contain images or anything other than text, and I don’t know if these can be stored in the TextField or not.
Of course, in the next step, I chose Base64 Upload Adapter
, which I don’t know exactly what it does
view:
class NewsCreateView(PermissionRequiredMixin, CreateView):
permission_required = 'news.add_news'
form_class = forms.NewsCreateForm
template_name = 'news/news_update_create.html'
def form_valid(self, form):
news_form = form.save(commit=False)
# Do something
news_form.author = self.request.user.profile
news_form.save()
return super().form_valid(form)