Django isn't finding my files in media/
<p>I am trying to create a webpage where users can fill out a form and email me their name, email address, a message, and an image.</p>

<p>My issue is getting the image attached to the email. When the code runs, the image is uploaded to my media root along with my other media files, but it throws an FileNotFoundError [Errno 2] No such file or directory: 'media/2016/10/14/image.png'</p>

<p>Here's my models.py:</p>

<pre><code>class UploadedImage(models.Model):
    uImage = models.FileField(upload_to='media/%Y/%m/%d')
</code></pre>

<p>forms.py:</p>

<pre><code>class QuoteForm(forms.Form):
    name = forms.CharField(required=True)
    from_email = forms.EmailField(required=True)
    uImage = forms.FileField(required=False, help_text='5mb max.')
    message = forms.CharField(widget=forms.Textarea)
</code></pre>

<p>views.py:</p>

<pre><code>def quote(request):
    form = QuoteForm(request.POST, request.FILES)
    if form.is_valid():
        name = form.cleaned_data['name']
        from_email = form.cleaned_data['from_email']
        message = form.cleaned_data['message']
        subject = "Quote"
        message = "From: " + name + "\n" + "Return Email: " + from_email + "\n" + "Subject: " + subject  + "\n" + "Message: " + message

        newImage = UploadedImage(uImage = request.FILES['uImage'])
        newImage.save()
        msg = EmailMessage(subject, message, from_email, ['zbloss@emich.edu'], reply_to=[from_email])
        image_url = newImage.uImage.url
        msg.attach_file(image_url)

        try:
            msg.send()
        except BadHeaderError:
            return HttpResponse('Invalid header found')
        return HttpResponseRedirect('/thankyou')
    return render(request, "quote.html", {'form': form})
</code></pre>

<p>You're passing a (non-existent) URL to <code>msg.attach_file</code>. You need to pass the location of the file on disk:</p>

<pre><code>msg.attach_file(os.path.join(settings.MEDIA_ROOT, newImage.uImage.name))
</code></pre>

python django forms email attachment