Error de Django CSRF después de la actualización 1.9> 1.11
Acabo de actualizar una aplicación que estoy desarrollando de 1.9 a 1.11 y recibo errores constantes en todas las publicaciones de formulario:
CSRF token missing or incorrect.
Todos los tokens CSRF funcionaban bien en 1.9. Aquí está la vista:
def contact(request):
subject = request.GET.get('subject', '')
contact_form = forms.ContactForm(subject=subject)
if request.POST:
contact_form = forms.ContactForm(request.POST)
if contact_form.is_valid():
new_contact = contact_form.save()
logic.send_contact_message(new_contact, request)
messages.add_message(request, messages.SUCCESS, 'Your message has been sent.')
return redirect(reverse('contact'))
template = 'journal/contact.html'
context = {
'contact_form': contact_form,
'contacts': core_models.Contacts.objects.filter(content_type=request.content_type,
object_id=request.site_type.pk)
}
return render(request, template, context)
Aquí está la plantilla:
<h4>{% trans "Contact" %}</h4>
<form method="POST">
{% include "elements/forms/errors.html" with form=contact_form %}
{% csrf_token %}
<label for="id_recipient">{% trans "Who would you like to contact?" %}</label>
<select id="id_recipient" name="recipient">
{% for contact in contacts %}<option value="{{ contact.email }}">{{ contact.name }}, {{ contact.role }}</option>{% endfor %}
</select>
{{ contact_form.sender|foundation }}
{{ contact_form.subject|foundation }}
{{ contact_form.body|foundation }}
{{ contact_form.are_you_a_robot|foundation }}
<button type="submit" class="success button">{% trans "Send Message" %}</button>
</form>