meong_j
기록하는 습관.
meong_j
전체 방문자
오늘
어제
  • 분류 전체보기 (176)
    • 개인 공부 정리 (0)
    • 서버 운영 (37)
      • Linux (36)
    • Frontend (11)
      • Vue.js (10)
    • Backend (70)
      • Java (4)
      • Python (22)
      • Django (38)
      • Spring (6)
    • Database (5)
      • Oracle (4)
      • MySQL (1)
      • MariaDB (0)
    • Android (14)
      • Kotlin (6)
    • 배포 (9)
      • Docker (8)
      • AWS (1)
    • IT_study (29)
      • Coding test (17)
      • 알고리즘 (5)
      • 스터디 (6)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • github

인기 글

반응형

태그

  • 안드로이드adaptor
  • 이차원배열정렬
  • 배포인프라
  • gabagecollecter
  • dp #알고리즘
  • dockersecret
  • DHCP
  • 테크커리어
  • 리눅스인증
  • docker
  • django
  • Kotlin
  • SASS Variables
  • router-link
  • 리눅스방화벽
  • 중첩라우트
  • 개발자도서
  • 코틀린자료형
  • cpu사용률
  • Proxy

최근 댓글

최근 글

250x250
hELLO · Designed By 정상우.
meong_j

기록하는 습관.

django 31. WYSIWYG 의 소개 및 적용
Backend/Django

django 31. WYSIWYG 의 소개 및 적용

2021. 10. 18. 19:41
728x90
반응형

프로젝트 목표

Medium Editor 를 사용하여 WYSIWYG를 통해 게시글 작성할 수 있도록 만들어본다.

 

WYSIWYG

게시판 기능 중 하나로 What You See Is What You Get(보는 대로 글이 써진다.) 의 약자이다.

텍스트를 변환 할 수 있는 기능을 제공해준다.

 

Medium Editor github: https://github.com/yabwe/medium-editor

 

GitHub - yabwe/medium-editor: Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution.

Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution. - GitHub - yabwe/medium-editor: Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a...

github.com

Demo : https://yabwe.github.io/medium-editor/

 

MediumEditor

MediumEditor The dead simple inline editor toolbar. Try highlighting this text. Or check the full demo.

yabwe.github.io

 

 

forms.py

from django.forms import ModelForm
from django import forms

from articleapp.models import Article
from projectapp.models import Project


class ArticleCreationForm(ModelForm):
    content = forms.CharField(widget=forms.Textarea(attrs={'class': 'editable ',
                                                           'style': 'height:auto;text-align : left'}))

    project = forms.ModelChoiceField(queryset=Project.objects.all(), required=False)

    class Meta:
        model = Article
        fields = ['title', 'image', 'project', 'content']
  • Textarea의 attrs는 미리 class와 style을 지정해줌
  • 프로젝트 Update 시 해당 프로젝트에 해당하는 프로젝트가 나오도록 설정
  • project 설정 안해도 정상적으로 수정가능하도록 required=False 지정

 

create.html , update.html 

<script src="//cdn.jsdelivr.net/npm/medium-editor@5.23.2/dist/js/medium-editor.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/medium-editor@5.23.2/dist/css/medium-editor.min.css" type="text/css" media="screen" charset="utf-8">


<script>var editor = new MediumEditor('.editable');</script>
  • WYSIWYG 설정 link , script 태그 추가

 

detail.html

        <div style="text-align : left">
            {{ target_article.content | safe }}
        </div>
  • safe 를 사용해 update시 태그<> 나오는 것 처리

 

  • WYSIWYG를 사용해 content 텍스트 변화 주고, 왼쪽 정렬 설정 페이지

 

  • content 지정한 그대로 (what you see) 텍스트로 보여짐(what you get)
반응형
저작자표시 비영리 변경금지 (새창열림)

'Backend > Django' 카테고리의 다른 글

Django message 구현  (0) 2021.12.02
django 30. Field Lookup을 사용한 구독 페이지 구현  (0) 2021.10.18
django 29. RedirectView을 통한 SubscribeApp시작  (0) 2021.10.13
django 28. MultipleObjectMixin을 통한 ProjectApp 마무리  (0) 2021.10.13
django 27. 모바일 디버깅, 반응형 레이아웃  (0) 2021.10.12
    'Backend/Django' 카테고리의 다른 글
    • Django message 구현
    • django 30. Field Lookup을 사용한 구독 페이지 구현
    • django 29. RedirectView을 통한 SubscribeApp시작
    • django 28. MultipleObjectMixin을 통한 ProjectApp 마무리
    meong_j
    meong_j
    #it #개발일기 #개발공부 #개발자 #백앤드 #생각정리 #시간은 실력에 비례한다 #뭐든지 꾸준히 열심히 #오늘의 내가 내일의 나를 만든다

    티스토리툴바