Blog with Django (Codemy.com) - 21 Rich Text Editor (django-ckeditor)

이다연·2021년 3월 31일
0

Django

목록 보기
25/33

1. install

install django-ckeditor
pip install django-ckeditor

2. models

Change body field of Post model
models.py

from ckeditor.fields import RichTextField

class Post(models.Model):
      body = RichTextField(blank=True, null=True)
    

makemigrations and migrate

3. templates

add_post.html

<div class="form-group">
    <form method="POST">
        {% csrf_token %}
        {{ form.media }}
        {{ form.as_p }}
        <br/>
        <button class="btn btn-secondary"> Post </button>
    </form>
</div>

update other templates such as update_post.html

4. Add app at settings.py

TemplateDoesNotExist error...
add ckeditor in settings.py
check virtual environment

INSTALLED_APPS = [

    'ckeditor',

5. |safe

add safe pipe, otherwise it will show all the html tags like so...

article_details.html

    {{ post.body|safe }}
profile
Dayeon Lee | Django & Python Web Developer

1개의 댓글

comment-user-thumbnail
2024년 4월 30일

There are many reasons for which one can choose to hire Aerocity Call Girls for their personal satisfaction. You can look for different options from Aerocity escorts agency and choose the best one for yourself.

답글 달기