[英]Django Summernote clean() got an unexpected keyword argument 'styles' in DjangoForms
I have a Django app hosted on Heroku. I have Summernotes installed on the Django forms, however, when I submit the forms I get the error: clean() got an unexpected keyword argument 'styles'我有一个 Django 应用程序托管在 Heroku 上。我在 Django forms 上安装了 Summernotes,但是,当我提交 forms 时,我收到错误:clean() 得到了一个意外的关键字参数'styles'
Exception Location: /app/.heroku/python/lib/python3.10/site-packages/django_summernote/fields.py, line 18, in to_python异常位置:/app/.heroku/python/lib/python3.10/site-packages/django_summernote/fields.py, line 18, in to_python
I can edit this file on the local host and remove styles=STYLES and it will work on localhost but I am unable to edit this on Heroku.我可以在本地主机上编辑此文件并删除 styles=STYLES,它将在本地主机上运行,但我无法在 Heroku 上编辑此文件。
This error also shows up if i try and edit via the admin.如果我尝试通过管理员进行编辑,也会出现此错误。
I'm lost on what to try next.我不知道接下来要尝试什么。 Thank you in advance.先感谢您。
from django.db import models
from django.forms import fields
import bleach
from django_summernote.settings import ALLOWED_TAGS, ATTRIBUTES, STYLES
from django_summernote.widgets import SummernoteWidget
# code based on https://github.com/shaunsephton/django-ckeditor
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, styles=STYLES)
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, styles=STYLES)
I do have this in the settings files but it doesn't do anything: STYLES = [ 'background-color', 'font-size', 'line-height', 'color', 'font-family' ]我在设置文件中确实有这个,但它没有做任何事情:STYLES = [ 'background-color', 'font-size', 'line-height', 'color', 'font-family' ]
My models.py我的模型.py
from django.db.models.signals import post_save, post_delete
from django.db import models
from model_utils import Choices
from django.contrib.auth.models import User
from django.conf import settings
User = settings.AUTH_USER_MODEL
import uuid
from django.db.models.deletion import CASCADE
from categories.models import Category
import datetime
from django.core.mail import send_mail
from django import forms
from django.forms import Form
from django_summernote.widgets import SummernoteWidget, SummernoteInplaceWidget
from django_summernote.fields import SummernoteTextFormField, SummernoteTextField
class Job(models.Model):
owner = models.ForeignKey(
Profile, on_delete=models.CASCADE, null=True, blank=True)
title = models.CharField(max_length=300, blank=True, null=True)
pay = models.CharField(max_length=200, blank=True, null=True)
location = models.CharField(max_length=300, blank=True, null=True)
description =SummernoteTextField()
benefits = models.CharField(max_length=300, blank=True, null=True)
closingdate = models.DateField( null=True, blank = True)
apply = models.CharField(max_length=300, blank=True, null=True)
created = models.DateTimeField(auto_now_add=True)
id = models.UUIDField(default=uuid.uuid4, unique=True,
forms.py forms.py
from django_summernote.widgets import SummernoteWidget, SummernoteInplaceWidget
from django_summernote.fields import SummernoteTextFormField, SummernoteTextField
class JobForm(ModelForm):
class Meta:
model = Job
fields = ['title', 'pay', 'location', 'description', 'benefits', 'apply']
labels = {'title': 'Title', 'pay': 'Pay', 'location':'Location', 'description': 'Description', 'benefits':'Benefits & Healthcare', 'apply': 'How to apply'}
Jobform.py工作表.py
{% extends 'main.html' %}
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote-bs5.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote-bs5.js"></script>
...
{{ form.media }}
</head>
{% block content %}
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-6 col-12">
<div class="section__header style-2 text-center wow fadeInUp" data-wow-duration="1.5s">
<div class="container">
<div class="main-content">
</div>
</div>
</div>
<!-- Main Section -->
<main class="formPage my-xl">
<div class="container">
<div class="row justify-content-center">
<h3>Create Job</h3>
<div class="content-box">
<div class="formWrapper">
<a class="backButton" href="{% url 'account' %}"><i class="im im-angle-left"></i></a>
<br>
<form class="form-group" method="POST" action="{% url 'create-job' %}" enctype="multipart/form-data">
{% csrf_token %}
{% for field in form %}
<div class="form__field">
<label for="formInput#text">{{field.label}}</label>
{{field}}
</div>
{% endfor %}
<div>
<br>
</div>
<input class="default-btn" type="submit" value="Submit" />
</form>
<div>
<br>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
</div> </div>
{% endblock content %}
try this pip install bleach-4.1.0
试试这个pip install bleach-4.1.0
github issues page: 5.x version of bleach causes an unexpected keyword argument github 问题页面:5.x 版本的漂白剂导致意外的关键字参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.