Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django ckeditor:表单中未加载数据_Python_Django_Django Ckeditor - Fatal编程技术网

Python django ckeditor:表单中未加载数据

Python 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

我使用Django ckeditor作为模型表单小部件。我能够使用模型表单保存数据

现在我想编辑任何保存的数据,表单不会将数据加载到CKeditor上。 Django 1.10 Python 3.5 Windows 7 64位

forms.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})
视图.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它也不起作用,也可以尝试将表单作为段落和表格