Django-尝试更新现有记录时我的表单为空

时间:2018-12-04 16:18:02

标签: django-forms

我正在尝试为我的项目实施更新功能。我正在使用2种表格更新记录,一种用于“问题”,另一种用于“响应”。

views.py:

@login_required(login_url="/login/")
def update(request, id):
    resp = Response.objects.select_related('Question').get(pk=id)
    quest = Question.objects.get(pk=resp.Question_id)
    qform = QuestionForm(request.POST or None, instance=quest)
    rform = ResponseForm(request.POST or None, instance=resp)
    rf = rform
    qf = qform

    if qform.is_valid() and rform.is_valid():
        qf = qform.save()
        rf = rform.save(commit=False)
        rf.Question = qf
        rf = rform.save()
        return redirect('../../search_es20')
    return render(request, 'app/update.html', {
        "rform": rf,
        "qform": qf,
    })

当我尝试更新记录时,它将带我到更新页面,但“问题和响应”字段显示为空白。

enter image description here

但是通过检查,它显示出文本区域中有文本:

<textarea name="Statement" cols="180" rows="1" required="" id="id_Statement">Non-functional (Automated Testing)</textarea>

enter image description here

如何使它出现在字段中?

0 个答案:

没有答案