Всем доброго времени суток!
У меня есть вот такой мейлер. Он работает нормально, письма приходят. Но, не приходят прикрепленные файлы. Скажите, что тут не так? Спасибо!
forms.py
class ContactForm(forms.Form):
name = forms.CharField(required=False, max_length=150, help_text="Name")
email = forms.CharField(required=False, max_length=150, help_text="Email")
file = forms.FileField(widget=forms.FileInput, required=False)
message = forms.CharField(widget=forms.Textarea, help_text="Text area")
views.py
@csrf_exempt
def contact_us(request):
if request.method == 'POST':
form = ContactForm(request.POST, request.FILES)
if form.is_valid():
sender_name = form.cleaned_data['name']
sender_email = form.cleaned_data['email']
sender_file = form.request.FILES['file']
message = "{0} New massege:\n\n{1}\n\n{2}\n\n{3}".format(sender_name,
sender_email,
form.cleaned_data['message'],
sender_file,)
send_mail('Subject', message, sender_email, ['to.my.mail@gmail.com'])
return render(request, 'pages/thank-you.html')
else:
form = ContactForm()
return render(request, 'flatpages/report.html', {'form': form})
HTML
<div class="col-12 col-md-6">
<div class="report">
<h3 class="report-title">Contact Form</h3>
<form method="post" action="/pro-upravlinnya/report/">
<div style="display:none">
<input type="hidden" name="csrfmiddlewaretoken" value="$csrf_token"/>
</div>
<div class="report-control">
{{ form.name.help_text }}
{{ form.name }}
</div>
<div class="report-control">
{{ form.email.help_text }}
{{ form.email }}
</div>
{{ form.file }}
<div class="report-control">
{{ form.message.help_text }}
{{ form.message }}
</div>
<div class="report-btn-wrp">
<button type="submit" class="report-submit" >Send</button>
</div>
</form>
</div>
</div>