0
我是新的Django用戶。當我在Django中運行程序時,我得到了這個錯誤,請幫忙。Django問題模板不存在/ deals/
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)
嘗試將最後一行更改爲'return render(request,'products/deals.html',context)'並將表單變量添加到您的上下文字典 –
嗨!感謝您的回覆。它的工作。錯誤已解決,但在這裏我在deals.html中有一個不顯示的表單。 –
這裏它的代碼<形式行動= 「/交易/」 方法= 「POST」 ENCTYPE = 「多部分/格式數據」> {%csrf_token%} {{form.as_p}} –