Why is my email template in Django sending the whole model and not just the values input
I'm trying to email a copy of my contact form when the form is saved, but the template tags seem to be pulling the full model not just the inputs. I have no idea what I'm doing wrong here.
My email template.txt file
Hi!
You received a message from {{ contact_form.name }} at {{ contact_form.email }}
{{ contact_form.message}}
My views.py
if request.method == "POST":
contact_form = ContactForm(request.POST, request.FILES)
if contact_form.is_valid():
contact_form.save(commit=False)
try:
contact_form.image_field_1 = request.FILES['image_field_1']
except:
contact_form.save()
try:
contact_form.image_field_2 = request.FILES['image_field_2']
except:
contact_form.save()
contact_form.save()
subject = 'Website enquiry'
body = render_to_string(
'contact_emails/contact_email_body.txt',
{'contact_form': contact_form,
})
send_mail(
subject,
body,
settings.DEFAULT_FROM_EMAIL,
['test@gmail.com'],
)
messages.success(request,
"Message received! \
We will respond as soon as possible!")
else:
contact_form = ContactForm()
This is what arrives in the email
Hi! You received a message from at
Testing again