FieldFile object does not have the rfind attribute

Im really new to Django, so I'm still used to forms. I am trying to send an email to Django using all cleared data from the form, including the file that is uploaded, and I get an error. The FieldFile object does not have the "rfind" attribute. when I try to attach a file to an email. Does this mean that the file must first be downloaded to a folder in my project so that the file path has a link?

Here is my form

class Application(forms.Form): first_name = forms.CharField(label="First Name", max_length=50) last_name = forms.CharField(label="Last Name", max_length=50) email = forms.EmailField(label="Email", max_length=80) phone = forms.CharField(label="Phone Number", max_length=30) resume = forms.FileField(label="Resume", max_length=1000) message = forms.CharField(label="Message", max_length=800, widget=forms.Textarea) 

My view

 if request.method == "POST": form = Application(request.POST, request.FILES) Post = True if form.is_valid(): cleaned_data = form.cleaned_data is_valid = True applicant = Applicant() applicant.first_name = cleaned_data['first_name'] applicant.last_name = cleaned_data['last_name'] applicant.email = cleaned_data['email'] applicant.phone = cleaned_data['phone'] applicant.resume = request.FILES['resume'] applicant.message = cleaned_data['message'] applicant.job = career.name date = datetime.datetime.now() applicant.save() email_context = {'interested': applicant} html_content = render_to_string("email/contact/application-html.html", email_context) email = EmailMessage('Some is interested in a demo with Atlas', html_content, settings.DEFAULT_FROM_EMAIL, [' timbaney1989@gmail.com ']) email.attach_file(applicant.resume) email.send(fail_silently=False) else: is_valid = False else: form = Application() Post = False is_valid = False 
+5
source share
1 answer

attach_file() takes a path as an argument, not a FieldFile . It should be:

 email.attach_file(applicant.resume.path) 
+4
source

Source: https://habr.com/ru/post/1245112/


All Articles