上下文未从views.py到达pythonDjango中的页面

2024-09-28 03:17:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Django应用程序,正在尝试将一些context views.py发送到特定页面:

status = True
context = {'status': status }
    return render(request, "sample/Newsample.html",{"form":ProfileForm() } ,context)

但是上下文没有到达Newsample.html。代码的语法有错误吗?ProfileForm()是我的forms.py中的某个方法,我认为它与上下文无关

有什么帮助吗


Tags: sampledjangopytrue应用程序returnrequesthtml
2条回答
status = True
context = {'status': status }
return render(request, "sample/Newsample.html",{"form":ProfileForm() } ,context)

应该是

status = True
context = {'status': status , 'form': ProfileForm()}
return render(request, "sample/Newsample.html", context)

render传递给模板的上下文是第三个参数,所以您需要根据需要更新代码

status = True
context = {'status': status ,
           "form":ProfileForm()
          }
    return render(request, "sample/Newsample.html", context)

相关问题 更多 >

    热门问题