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
2023년 8월 1일

The escorts are very friendly and thus you would find that starting for the time of introduction till the final sensational activities you would feel the level of comfort to a great extent. All those who are in the business of Mumbai Independent Escorts can be hired by the people to be the paid companion and make them satisfied in every possible manner.
https://www.heenasehgal.in/colaba-call-girls.html
https://www.heenasehgal.in/churchgate-call-girls.html
https://www.heenasehgal.in/chembur-call-girls.html
https://www.heenasehgal.in/byculla-call-girls.html

답글 달기