I keep getting the above error (in the title) for my DeleteView.
Strangely my UpdateView, UpdateObject form and update_object template are identical to my DeleteView, DeleteObject form and delete_object template respectively. I'm not sure why bootstrap is giving me an error for this form and not my update form?
Here are the files:
forms.py:
from django import forms
from . import models
from django.forms import ModelForm
class CreateBouquetForm(ModelForm):
class Meta:
model = models.Bouquet
exclude = ('price',)
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
class UpdateBouquetForm(ModelForm):
class Meta:
model = models.Bouquet
exclude = ('price',)
class DeleteBouquetForm(ModelForm):
class Meta:
model = models.Bouquet
exclude = ('price',)
`
views.py:
class UpdateBouquet(UpdateView):
model = models.Bouquet
form_class = forms.UpdateBouquetForm
template_name = 'products/update_bouquet.html'
success_url = reverse_lazy('products:shop')
def form_valid(self,form):
self.object = form.save(commit=False)
result = 0
for flower in self.object.flower.all():
result += flower.price
self.object.price = result
self.object.save()
return super().form_valid(form)
class DeleteBouquet(DeleteView):
model = models.Bouquet
form_class = forms.DeleteBouquetForm
template_name = 'products/delete_bouquet.html'
success_url = reverse_lazy('products:shop')
products/update_bouquet.html:
{% extends 'site_base.html' %}
{% load bootstrap3 %}
{% block content_block %}
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
<input type="submit" class="btn btn-outline-success" value="Save bouquet and continue shopping">
</form>
<h6><a href="{% url 'products:detail_bouquet' pk=bouquet.pk %}">Back to bouquet</a></h6>
{% endblock %}
products/delete_bouquet.html:
{% extends 'site_base.html' %}
{% load bootstrap3 %}
{% block content_block %}
<h5>Are you sure you want to delete your bouquet?</h5>
<form method="POST">
{% csrf_token %}
{% bootstrap_form form %}
<input type="submit" class="btn btn-outline-success" value="Delete">
</form>
<h6><a class="btn btn-outline-danger" href="{% url 'products:detail_bouquet' pk=bouquet.pk %}">Cancel</a></h6>
{% endblock %}
urls.py:
url(r'^bouquet/(?P<pk>d+)/update/$',views.UpdateBouquet.as_view(),name="update_bouquet"),
url(r'^bouquet/(?P<pk>d+)/delete/$',views.DeleteBouquet.as_view(),name="delete_bouquet"),
Here's what the error page says:
Error during template rendering
In template C:UsersjoannDesktopFlowers_Storefrontstorefrontemplatessite_base.html, error at line 8
Parameter "form" should contain a valid Django Form.
1 <!DOCTYPE html>
2 {% load static %}
3 {% load bootstrap3 %}
4 <html lang="en" dir="ltr">
5 <head>
6 <meta charset="utf-8">
7 <title></title>
8 <link href="https://cdn.jsdelivr.net/**npm/[email protected]/dist/css/boo**tstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
9 <link rel="stylesheet" href="{% static "/css/css_master.css" %}">
10 <link rel="preconnect" href="https://fonts.gstatic.com">
11 class="container-fluid">
...etc....
Thanks in advance if you can help!