How can my user upload an image to email to me [Django]
<p>I've got a simple website for a Screenprinting company built using Django 1.10 and Python 3.5.2, but I am having issues with my "Get a Quote" page.</p>

<p>The idea is a user can go to www.example.com/quote/ and they are presented with a form. Here they put in their Name, Email Address, a Brief Message, and most importantly they can upload an image. </p>

<p>When they click submit, this data gets sent to my email address as an email using the EmailMessage method. I have set up a simple email form plenty of times in the past so I know my settings.py file is fine.</p>

<p>Here is my forms.py:</p>

<pre><code>class QuoteForm(forms.Form):
name = forms.CharField(required=True)
from_email = forms.EmailField(required=True)
subject = "Quote"
uploaded_image = forms.ImageField()
message = forms.CharField(widget=forms.Textarea)
</code></pre>

<p>Here is my views.py:</p>

<pre><code>def quote(request):
form = QuoteForm(request.POST)
if form.is_valid():
    name = form.cleaned_data['name']
    from_email = form.cleaned_data['from_email']
    message = form.cleaned_data['message']
    message = "From: " + name + "\n" + "Return Email: " + from_email + "\n" + "Subject: " + subject + "\n" + "Message: " + message
    uploaded_image = form.cleaned_data['uploaded_image']
    msg = EmailMessage(subject, message, from_email, ['example@email.com'], reply_to=[from_email])
    msg.attach_file(uploaded_image)
    try:
        msg.send()
    except BadHeaderError:
        return HttpResponse('Invalid header found')
    return HttpResponseRedirect('thankyou')
return render(request, "quote.html", {'form': form})
</code></pre>

<p>When I test this on 127.0.0.1 I click submit and the form refreshes with the same info, except the image is no longer there.</p>

<p>Also, When I test it using the console.EmailBackend there are no errors. In fact, clicking submit doesn't seem to have any effect other than it reloads a few css files.</p>

<p>Any ideas?</p>

<p>A file is not in the <code>request.POST</code> attribute, it is in <code>request.FILES</code>. Your <code>views.py</code> should look like this:</p>

<pre><code>def quote(request):
    form = QuoteForm(request.POST, request.FILES)
    if form.is_valid():
        ...
        uploaded_image = request.FILES.getlist('uploaded_image')
        ...
</code></pre>

<p>Please note that this is a raw draft. I haven't tested it. Also note that you might have to sanitize the file for your own safety. For example: checking on the maximum filesize and contenttype.</p>

<p>More information about all of this: <a href="https://docs.djangoproject.com/en/1.10/topics/http/file-uploads/" rel="nofollow">https://docs.djangoproject.com/en/1.10/topics/http/file-uploads/</a></p>

python django email upload imagefield