Python django ckeditor:表单中未加载数据
我使用Django ckeditor作为模型表单小部件。我能够使用模型表单保存数据 现在我想编辑任何保存的数据,表单不会将数据加载到CKeditor上。 Django 1.10 Python 3.5 Windows 7 64位 forms.pyPython django ckeditor:表单中未加载数据,python,django,django-ckeditor,Python,Django,Django Ckeditor,我使用Django ckeditor作为模型表单小部件。我能够使用模型表单保存数据 现在我想编辑任何保存的数据,表单不会将数据加载到CKeditor上。 Django 1.10 Python 3.5 Windows 7 64位 forms.py class templateform(forms.ModelForm): class Meta: model = presciptiontemplates fields = ['template', 'templa
class templateform(forms.ModelForm):
class Meta:
model = presciptiontemplates
fields = ['template', 'templateid', ]
widgets = {
'template': CKEditorWidget(),
}
labels = {
"templateid": _("Patient ID"),
}
def get_template(request, tid):
template = presciptiontemplates.objects.get(templateid=tid)
form = templateform(request.POST, instance=template)
if form.is_valid():
form = form.save(commit=False)
form.patientid = tid
form.save()
else:
form = templateform(request.POST, instance=template)
return render(request, 'presapp/viewtemplate.html',{'form': form})
视图.py
class templateform(forms.ModelForm):
class Meta:
model = presciptiontemplates
fields = ['template', 'templateid', ]
widgets = {
'template': CKEditorWidget(),
}
labels = {
"templateid": _("Patient ID"),
}
def get_template(request, tid):
template = presciptiontemplates.objects.get(templateid=tid)
form = templateform(request.POST, instance=template)
if form.is_valid():
form = form.save(commit=False)
form.patientid = tid
form.save()
else:
form = templateform(request.POST, instance=template)
return render(request, 'presapp/viewtemplate.html',{'form': form})
HTML
<div id="preview-content">
<form method="post" style="margin-top:20px;">
{% csrf_token %}
{{ form.media }}
{{ form|safe }}
<div class="" style="margin-top:20px ;">
<button class="btn waves-effect waves-light left" type="submit">Submit
<i class="material-icons right">add_circle</i
</button>
</form>
</div>
</div>
{%csrf_令牌%}
{{form.media}
{{形式|安全}
提交
add_circletry removing | safe只需使用{{form}@SandeepBalagopal它也不起作用,也可以尝试将表单作为段落和表格