【问题标题】:django-ckeditor :data not loading in the Formdjango-ckeditor:数据未加载到表单中
【发布时间】:2017-04-18 12:31:39
【问题描述】:

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

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

forms.py

class templateform(forms.ModelForm):
    class Meta:
        model = presciptiontemplates
        fields = ['template', 'templateid', ]
        widgets = {
            'template': CKEditorWidget(),
        }
        labels = {
            "templateid": _("Patient ID"),
            }

views.py

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>

【问题讨论】:

  • 尝试删除 |safe just use {{ form }}
  • @SandeepBalagopal 它也不能那样工作还尝试将表单作为段落和表格

标签: python django django-ckeditor


【解决方案1】:

将 {{ form|safe }} 更改为 {{ form.as_p }}

<div id="preview-content">
        <form method="post" style="margin-top:20px;">
            {% csrf_token %}
             {{ form.media }}
             {{ form.as_p }}
            <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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-28
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 2017-03-12
    • 2021-07-24
    • 1970-01-01
    • 2014-11-16
    相关资源
    最近更新 更多