Django CKEditor работает не во всех полях textarea

Я пытался использовать Django CKEditor для улучшения моего текстового редактора. Это выглядит хорошо, однако не на все мои поля textarea может повлиять Django CKEditor. Он воздействует только на первое, на остальные - нет. Вот мои рисунки и код. Надеюсь, вы сможете помочь мне решить эту проблему. Спасибо!

введите описание изображения здесь

введите описание изображения здесь

post-detail.html

<section id="comments">
{% for child_comment in comment.children %}
            <div class="child-comment">
                <a href="mailto:{{ comment.user.email }}" style="text-decoration: none;">{{ child_comment.author }}</a>
                <span style="font-style: italic;">{{child_comment.timestamp}}</span>
                <p>{{child_comment.text|safe}}</p>
            </div>
            
{% endfor %}
</section>

<section id="comment-form">
        <form action="{% url 'post-detail-page' post.slug %}" method="POST" enctype="multipart/form-data">
            {% csrf_token %}
            {% for form_field in comment_form %} 
                 <div class="form-control {% if form_field.errors %}invalid{% endif %}">
                    {{ form_field.label_tag }}
                    {{ form_field }}
                    {{ form_field.errors }}
                    {{ form.media }}
                </div>  
            <button>Submit</button>
            {% endfor %} 
            
        </form> 
</section>

<script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
<script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>

views.py

@class_view_decorator(login_required)
class PostDetailView(View, LoginRequiredMixin):
    def is_marked_post(self, request, post_id):
        marked_posts = request.session.get('marked_posts')
        if marked_posts is not None:
            is_saved_for_later = post_id in marked_posts
        else:
            is_saved_for_later = False

        return is_saved_for_later

    def get(self, request, slug):
        post = Post.objects.get(slug=slug)

        context = {
            "post": post,
            "post_tags": post.tags.all(),
            "comment_form": CommentForm(),
            "comments": post.comments.all().order_by("-id"),
            "saved_for_later": self.is_marked_post(request, post.id)
        }
        return render(request, "blog/post-detail.html", context)

    def post(self, request, slug):
        comment_form = CommentForm(request.POST)
        post = Post.objects.get(slug=slug)   

        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.post = post
            comment.author = request.user
            comment.save()

            return HttpResponseRedirect(reverse("post-detail-page", args=[slug]))

        context = {
            "post": post,
            "post_tags": post.tags.all(),
            "comment_form": CommentForm(),
            "comments": post.comments.all().order_by("-id"),
            "saved_for_later": self.is_marked_post(request, post.id)
        }
        return render(request, "blog/post-detail.html", context)

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['post_tags'] = self.object.tags.all()
        context['comment_form'] = CommentForm()
        return context

@class_view_decorator(login_required)
class CommentReplyView(View):
    def post(self, request, slug, pk):
        post = Post.objects.get(slug=slug)
        parent_comment = Comment.objects.get(pk=pk)
        form = CommentForm(request.POST)

        if form.is_valid():
            new_comment = form.save(commit=False)
            new_comment.post = post
            new_comment.parent = parent_comment
            new_comment.author = request.user
            new_comment.save()
    
        return redirect('post-detail-page', slug=slug)
        

forms.py

from django import forms
from django.forms import fields
from .models import Comment

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        exclude = ["post", "parent", "author"]
        labels = {
            # "title": "Title",
            "text": "Your comment"
        }

Вернуться на верх