You're right, it's not very clear how to have a single class-based view
handle both displaying details and submitting a form. This is a
fantastic site that shows how each class based view is set up
inheritance-wise: https://ccbv.co.uk/
Take a look the ancestors for DetailView:
https://ccbv.co.uk/projects/Django/4.0/django.views.generic.detail/DetailView/
... and the ancestors for FormView:
https://ccbv.co.uk/projects/Django/4.0/django.views.generic.edit/FormView/
Maybe you can just add the FormMixin as an ancestor to your DetailView.
As another option, maybe you can create a separate FormView that you can
POST to from your DetailView.
- Ryan N
On 4/26/22 5:25 AM, alex smolyakov wrote:
Can anyone explain me how to make send email form on page.
So my forms.py
class ContactForm(forms.Form):
name = forms.CharField(required=True)
last_name = forms.CharField()
adults = forms.IntegerField() children = forms.IntegerField()
email = forms.EmailField(required=True)
message = forms.CharField(widget=forms.Textarea)
views.py
class TourDetailView(DetailView):
model = models.Tour
template_name = 'tours/tour-detail.html'
form_class = forms.ContactForm
success_url = 'tours.html'
As far as i understand i need to get data from request , but i dont
know how to do it. There are a lot of information in function based
views, but i didnt get how to do it in class based views.
And it would be nice of you to explain where should i put send_mail
function. Any help will be appreciated.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/235da153-a9d7-2582-ace4-3dbf147d17f8%40fattuba.com.