Python Django-RichText-Ckeditor-如何更新网站内容
我花了很多时间试图解决这个问题,但是我找不到关于如何在网站上的CKEditor中更新数据的好教程(不是在Django的admin中) 我使用的是普通文本字段或文本框,我只需加载获取数据并将其放在属性值下,站点将在文本框中显示它,然后我可以编辑它并将其发回 但我正在努力解决如何将模型中的数据放在CKEditor中进行查看和现场查看,以便我可以对其进行更改。 我的环境如下所示: Forms.pyPython Django-RichText-Ckeditor-如何更新网站内容,python,django,django-models,django-forms,ckeditor,Python,Django,Django Models,Django Forms,Ckeditor,我花了很多时间试图解决这个问题,但是我找不到关于如何在网站上的CKEditor中更新数据的好教程(不是在Django的admin中) 我使用的是普通文本字段或文本框,我只需加载获取数据并将其放在属性值下,站点将在文本框中显示它,然后我可以编辑它并将其发回 但我正在努力解决如何将模型中的数据放在CKEditor中进行查看和现场查看,以便我可以对其进行更改。 我的环境如下所示: Forms.py class TestingContent(forms.ModelForm): content
class TestingContent(forms.ModelForm):
content = forms.CharField(widget=CKEditorWidget(
attrs={
'width':'100%',
}
)
)
class GITCTesting(models.Model):
text = RichTextField(default="Not_set")
.
.
.
def gitc_testing_detail(request, Testing_id, GITC_id):
gitctask = GITCTask.objects.filter(Q(idofgitc=GITC_id) & Q(related_control_id=Testing_id))
gitccontrol = GITCTesting.objects.get(Q(idofgitc=GITC_id) & Q(id=Testing_id))
post = get_object_or_404(GITCTesting, id=Testing_id)
form = TestingContent(request.POST or None, request.FILES or None, instance=post)
return render(request, 'rc_new/rcda_testing_detail.html', menu_contex)
型号.py
class TestingContent(forms.ModelForm):
content = forms.CharField(widget=CKEditorWidget(
attrs={
'width':'100%',
}
)
)
class GITCTesting(models.Model):
text = RichTextField(default="Not_set")
.
.
.
def gitc_testing_detail(request, Testing_id, GITC_id):
gitctask = GITCTask.objects.filter(Q(idofgitc=GITC_id) & Q(related_control_id=Testing_id))
gitccontrol = GITCTesting.objects.get(Q(idofgitc=GITC_id) & Q(id=Testing_id))
post = get_object_or_404(GITCTesting, id=Testing_id)
form = TestingContent(request.POST or None, request.FILES or None, instance=post)
return render(request, 'rc_new/rcda_testing_detail.html', menu_contex)
View.py
class TestingContent(forms.ModelForm):
content = forms.CharField(widget=CKEditorWidget(
attrs={
'width':'100%',
}
)
)
class GITCTesting(models.Model):
text = RichTextField(default="Not_set")
.
.
.
def gitc_testing_detail(request, Testing_id, GITC_id):
gitctask = GITCTask.objects.filter(Q(idofgitc=GITC_id) & Q(related_control_id=Testing_id))
gitccontrol = GITCTesting.objects.get(Q(idofgitc=GITC_id) & Q(id=Testing_id))
post = get_object_or_404(GITCTesting, id=Testing_id)
form = TestingContent(request.POST or None, request.FILES or None, instance=post)
return render(request, 'rc_new/rcda_testing_detail.html', menu_contex)
HTML模板
<div class="row">
{{ form.media }}
{{ form.content}}
</div>
{{form.media}
{{form.content}
我基本上试图在视图中的表单中创建“instance=post”,但我得到了一个参数,它不是预期的参数。
我试图更改一些代码,但遇到另一个错误“ModelForm没有指定模型类”
我也试图在互联网上找到一些东西,但我确实找到了一些有用的东西。有人能帮我吗?