Django问题模板不存在于/ deals /

时间:2015-08-14 11:28:10

标签: django django-models django-forms django-views

我是新的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)

1 个答案:

答案 0 :(得分:1)

你的错误是render函数的参数,它等待

之类的参数

render(request, 'name_of_template.html', context_dict)

另外,请检查form字典中必须包含的context变量,尝试按照这种方式添加它,然后再将其传递给渲染:

context['form'] = form

这些事情现在应该有效。