반응형
TypeError: clean() got an unexpected keyword argument 'styles'
edit django_summernote/fields.py
pip install tinycss2
vi .venv/lib/python3.12/site-packages/django_summernote/fields.py
# fields.py
# bleach.clean 함수가 styles 인수를 지원하지 않는 것 같습니다. bleach.clean 함수의 인수 목록을 확인하고, styles 인수를 제거하거나 다른 방법으로 스타일을 처리해야 합니다.
from django.db import models
from django.forms import fields
import bleach
from bleach.css_sanitizer import CSSSanitizer
from django_summernote.settings import ALLOWED_TAGS, ATTRIBUTES
from django_summernote.widgets import SummernoteWidget
# code based on https://github.com/shaunsephton/django-ckeditor
# CSSSanitizer 설정
css_sanitizer = CSSSanitizer(allowed_css_properties=['color', 'font-weight', 'font-style', 'text-decoration'])
class SummernoteTextFormField(fields.CharField):
def __init__(self, *args, **kwargs):
kwargs.update({'widget': SummernoteWidget()})
super().__init__(*args, **kwargs)
def to_python(self, value):
value = super().to_python(value)
return bleach.clean(
value, tags=ALLOWED_TAGS, attributes=ATTRIBUTES, css_sanitizer=css_sanitizer)
class SummernoteTextField(models.TextField):
def formfield(self, **kwargs):
kwargs.update({'form_class': SummernoteTextFormField})
return super().formfield(**kwargs)
def to_python(self, value):
value = super().to_python(value)
return bleach.clean(
value, tags=ALLOWED_TAGS, attributes=ATTRIBUTES, css_sanitizer=css_sanitizer)
def from_db_value(self, value, expression, connection):
if value is None:
return value
return bleach.clean(
value, tags=ALLOWED_TAGS, attributes=ATTRIBUTES, css_sanitizer=css_sanitizer)
'Code > Django' 카테고리의 다른 글
wagtail 첫번째 앱과 모델 만들기. (0) | 2024.08.21 |
---|---|
wagtail models.py > models/<modelname>.py 분리하기 (0) | 2024.08.19 |
django wagtail에서 ajax 구현 방식 (0) | 2024.07.31 |
wagtail MEDIA_URL 연결 (0) | 2024.07.29 |
url view 추가하기 CBV ( ListView) (0) | 2024.07.01 |