【发布时间】:2019-06-11 21:28:28
【问题描述】:
尝试使用 tinyMCE 在博客内容中实现丰富的输入。我受到限制,因为我在使用 django 1.11.20 的 Messanine 内部。 tinyMCE 似乎有很多版本,因此很难在 Google 上找到正确的解决方案。
我使用 Fosstack 的文档来安装 django-tinymce4-lite。然后将其集成到现有的更新博客表单中。表单没有显示更改,它仍然呈现为标准 CharField。 (这个版本的django不支持TextField)
在views.py中
class TinyMCEWidget(TinyMCE):
` def use_required_attribute(self, *args): 返回错误
class UpdateForm(forms.ModelForm):
content = forms.CharField(
widget=TinyMCEWidget(
attrs={'required': False, 'cols': 30, 'rows': 10}
)
)
class Meta:
model = BlogPost
fields = ['content']
def UpdateContent(request, slug):
blog_post = BlogPost.objects.get(id=slug)
if request.method == 'POST':
form = UpdateForm(request.POST)
if form.is_valid():
blog_post.content = form.cleaned_data['content']
blog_post.save()
return HttpResponseRedirect('/write/')
else:
form = UpdateForm(instance=blog_post)
return render(request, 'blog_my_update.html', {'form' : form})
在 blog_my_update.html 中
<h1>Update Story</h1>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
` 更新故事
我希望看到 tinyMCE 呈现表单。但是有一个普通的文本框。有人知道怎么修这个东西吗?提前致谢。
【问题讨论】: