Django/Sendgrid Form HTTP Error 400: Bad Request
<p>I'm getting an <code>HTTPError: HTTP Error 400: Bad Request</code> error when I try to send my Django form using Sendgrid. I have confirmed that there is a Sendgrid key in the envvars. Here is my code:</p>

<p><strong>settings.py</strong></p>

<pre><code># sendgrid
EMAIL_BACKEND = "sgbackend.SendGridBackend"
SENDGRID_API_KEY = get_env_variable('SENDGRID_KEY')
</code></pre>

<p><strong>urls.py</strong></p>

<pre><code>from __future__ import absolute_import, unicode_literals

from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin

from search import views as search_views
from wagtail.wagtailadmin import urls as wagtailadmin_urls
from wagtail.wagtailcore import urls as wagtail_urls
from wagtail.wagtaildocs import urls as wagtaildocs_urls

from wagtail.contrib.wagtailsitemaps.views import sitemap

urlpatterns = [
    url(r'^django-admin/', include(admin.site.urls)),

    url(r'^admin/', include(wagtailadmin_urls)),
    url(r'^documents/', include(wagtaildocs_urls)),

    url(r'^search/$', search_views.search, name='search'),

    url('^sitemap\.xml$', sitemap),

    url(r'', include(wagtail_urls)),
]


if settings.DEBUG:
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns

    # Serve static and media files from development server
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
</code></pre>

<p><strong>contact_form.html</strong></p>

<pre><code>{% load static %}

{% load app_tags %}

&lt;div id="contact-form"&gt;
  &lt;p class="thank-you" style='display:none;color:#ee9836;'&gt;Thank you for your message. We'll be in contact with you soon.&lt;/p&gt;
  &lt;form role="form" action="" method="post" class="form panel-body"&gt;
    {% csrf_token %}
    {{ form }}
    &lt;button class="btn btn-primary pull-right" type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
&lt;/div&gt;
</code></pre>

<p>My form view is in a template tag:</p>

<p><strong>app_tags.py</strong></p>

<pre><code>from django import template

from django.shortcuts import render, redirect
from django.template.loader import get_template
from django.core.mail import EmailMessage
from django.template import Context

from .forms import ContactForm

register = template.Library()

# contact form for footer
@register.inclusion_tag('contact_form.html')
def contact(request):
   form = ContactForm

   if request.method == 'POST':
        contact_form = form(data=request.POST)

        if contact_form.is_valid():
            contact_name = request.POST.get('name', '')
            contact_email = request.POST.get('email', '')
            contact_message = request.POST.get('message', '')

            # Email the profile with the
            # contact information
            template = get_template('contact_template.txt')
            context = Context({
                'contact_name': contact_name,
                'contact_email': contact_email,
                'contact_message': contact_message,
            })
            content = template.render(context)
            print content
            email = EmailMessage(
                "Contact Form",
                content,
                "contact@site.com" +'',
                ['email@sample.com'],
                headers = {'Reply-To': contact_email }
            )
            email.send()
   else:
       contact_form = form()

   return {'form': form}
</code></pre>

<p><strong>contact_template.txt</strong></p>

<pre><code>Contact Name:
{{ contact_name }}

Email:
{{ contact_email }}

Message:
{{ contact_message }}
</code></pre>

<p>Here's a bit of the traceback:</p>

<pre><code>    return opener.open(request)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 400: Bad Request
</code></pre>