Answer the question
In order to leave comments, you need to log in
How to output CKeditor to form in Django?
Hello.
Can you suggest the logic of how to display CKeditor in a form template? I do according to their manual, but the editor does not appear in the template, only in the admin panel. It seems to me that I do not understand and miss something.
What am I doing:
from django import forms
from ckeditor.widgets import CKEditorWidget
class Topic_Form(forms.Form):
topic_title = forms.CharField(label='Заголовок темы')
topic_text = forms.CharField(widget=CKEditorWidget, label='Ваш вопрос')
def forum_new_topic(request, topic_id):
form = Topic_Form(request.POST)
forum_category = str(topic_id)
context = {
"forum_category" : forum_category,
"form" : form,
}
return render(request, 'faceset/forum_new_topiс.html', context)
<form action="/#" method="post">
{% csrf_token %}
{{ form.topic_title.label_tag }}
{{ form.topic_title }}
{{ form.topic_text.label_tag }}
{{ form.topic_text.media }}
<input type="submit" class="expanded button" value="ОПУБЛИКОВАТЬ">
</form>
{% load staticfiles %}
{% load banner %}
<!doctype html>
<!--suppress ALL -->
<html class="no-js" lang="ru">
<head>
</head>
<body>
<div class="row">
<form action="/#" method="post">
{% csrf_token %}
{{ form.media }}
<input type="hidden" name="category" value="{{ forum_category }}">
<input type="submit" class="expanded button" value="ОПУБЛИКОВАТЬ">
</form>
</div>
</body>
</html>
Добавляем так и работает.
Answer the question
In order to leave comments, you need to log in
forms.py:
from ckeditor.widgets import CKEditorWidget
from django import forms
class PostEditForm(forms.Form):
content = forms.CharField(widget=CKEditorWidget, label='')
<form ...>
{{ post_form.media }}
...
</form>
def view(request):
post_form= PostEditForm(request.POST)
context = {
"post_form" : post_form,
}
return render(request, 'template.html', context)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question