I have written a function where the function captures the details from a form and sends an email after form submission. How can I have this functionality rendered to multiple django templates where i can call the form and do so. Below is the related function..
def emailView(request):
if request.method == 'GET':
form = myform()
else:
form = myform(request.POST)
if form.is_valid():
subject='form Details'
mobile = form.cleaned_data['mobile']
email = form.cleaned_data['email']
dummy = '\nMobile: '+mobile+'\nEmail: '+email'
try:
send_mail(subject, dummy, 'dummy@gmail.com', ['dummy1@gmail.com', 'dummy2@gmail.com'])
messages.success( request, " Thank you !! For contacting.')
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('email')
return render(request, "my_app/email.html", {'form': form})