I have a class-based view on my django app that grabs quote requests that are filled in the form and stores that information in the database.
I'd like to use send myself and email when somebody does that and include the data in the mail subject and message.
I got the e-mail part right and I can send a predefined message. but can't find a way to use the entered information.
Here's what I have so far:
urls.py
urlpatterns = [
path('', views.index, name='index'),
path('quote/', QuoteCreateView.as_view(), name='quote'),
path('quote/thankyou/', views.quoteThankyou, name='quote_thankyou'),
]
views.py
class QuoteCreateView(CreateView):
login_required = False
model = Quote
fields = ['fullname','email','date','description']
def form_valid(self,form):
form.instance.author = self.request.user
return super().form_valid(form)
def quoteThankyou(request):
subject = 'Message subject'
message = 'Message'
send_mail(
subject,
message,
'sender@email.com',
['receiver@email.com'],
fail_silently=False,
)
return render(request,'blog/quote_thankyou.html')
models.py
class Quote(models.Model):
fullname = models.CharField(max_length=100)
email = models.EmailField(max_length=100)
date_sent = models.DateTimeField(default=timezone.now)
date = models.DateTimeField()
description = models.TextField()
def __str__(self):
return self.fullname
def get_absolute_url(self):
return reverse('quote_thankyou', kwargs={})
I appreciate your help.