My Models
class ContactUs(models.Model):
name = models.CharField(max_length=120)
email = models.EmailField(max_length=120)
subject = models.TextField(max_length=200)
message = models.TextField(max_length=1000)
My Template
<div class="col-md-8">
<h4 class="m-t-0">Contact Form</h4>
<p class="m-b-30 f-s-13">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur lobortis tortor justo, elementum volutpat ante porta eu.
Sed eget tellus neque. Nam feugiat magna turpis. Vestibulum pharetra nibh et pretium efficitur. Donec porta sollicitudin laoreet.
Sed a condimentum urna. Curabitur placerat ornare venenatis. Cras iaculis venenatis imperdiet.
</p>
<form class="form-horizontal" name="contact_us_form" method="POST">
{% csrf_token %}
{{form.as_p}}
<div class="form-group">
<div class="col-md-offset-3 col-md-7">
<button type="submit" class="btn btn-inverse btn-lg">Send Message</button>
</div>
</div>
</form>
</div>
My Forms
class ContactForm(forms.ModelForm):
class Meta:
model = ContactUs
fields = '__all__'
widgets = {
'name': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Name'}),
'email': forms.EmailInput(attrs={'class': 'form-control', 'placeholder': 'Email'}),
'subject': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Subject'}),
'message': forms.Textarea(attrs={'class': 'form-control', 'rows': 10, 'placeholder': 'Message'}),
}
My VIews
class ContactTemplate(FormView):
template_name = 'contact_us.html'
form_class = ContactForm
success_url = '/products/'
def form_valid(self, form):
# Handle form submission
form.save()
return super().form_valid(form)
Error
TypeError at /contactus/
super(type, obj): obj must be an instance or subtype of type
Request Method: POST
Request URL: http://127.0.0.1:1200/contactus/
Django Version: 4.2.5
Exception Type: TypeError
Exception Value:
super(type, obj): obj must be an instance or subtype of type
Exception Location: /home/hamza/PycharmProjects/ecommercewebiste/EcomProject/shope/views.py, line 112, in post
Raised during: shope.views.ContactTemplate
Python Executable: /home/hamza/PycharmProjects/ecommercewebiste/Ecom_enva/bin/python
Python Version: 3.10.12
Python Path:
['/home/hamza/PycharmProjects/ecommercewebiste/EcomProject',
'/usr/lib/python310.zip',
'/usr/lib/python3.10',
'/usr/lib/python3.10/lib-dynload',
'/home/hamza/PycharmProjects/ecommercewebiste/Ecom_enva/lib/python3.10/site-packages']
Server time: Sun, 22 Oct 2023 09:02:53 +0000