Update view using function based view

痴心易碎 提交于 2019-12-04 19:02:27

Just get the object from model and pass that object as instance to the form. Then pass the form to the template. Write your view like below example.

def func(request, id):

    object = Model.objects.get(id=id)
    form = ModelForm(instance=object)

    return render(request, 'my_template.html', {'form':form})
coderknight439

Here, I tried something....

def approveform(request, pk):

    if pk:

        form = Admission.objects.get(pk=pk)

        p = Admission.objects.get(pk=pk)

        form = ApproveForm(instance=form)

    return render(
        request,
        'Automation/formapprove.html',
        {
            'year': datetime.now().year,
            'form': form,
            'test': p,
        }
    )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!