我是新的Django用户。当我在Django中运行程序时,我得到了这个错误,请帮助。
Template Does Not Exist at /deals/
{'form': <DealsForm bound=False, valid=Unknown, fields=(name;pages;email)>}
view.py
class DealsForm(ModelForm):
class Meta:
model = Book
fields = ['name','pages','email']
def deals(request):
products = Product.objects.all()
form = DealsForm()
context = {'products': products}
if request.method == "POST":
form = DealsForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('products/deals')
else:
form = DealsForm()
return render('products/deals.html',{'form': form}, context_instance=context)
答案 0 :(得分:1)
你的错误是render
函数的参数,它等待
render(request, 'name_of_template.html', context_dict)
另外,请检查form
字典中必须包含的context
变量,尝试按照这种方式添加它,然后再将其传递给渲染:
context['form'] = form
这些事情现在应该有效。