I have a problem with CSRF. I know must use: {% csrf_token %} but the problem is the same.
This my form:
For the {% csrf_token %}
tag to work, you must ensure that the template is rendered with the request object (see the docs).
The easiest way to do this is to use the render shortcut instead of render_to_response. The render_to_response
method is not recommended, and is likely to be removed from Django in future.
from django.shortcuts import render
def registro(request):
c = {}
# put any other context you need in c
# no need for c.update(csrf(request)) because we're using render
return render(request, 'registro.html', c)
You need to update any views that use csrf_token in their templates. In this case, you haven't updated the home
view that renders the form in the index.html
template.
def home(request):
articulos = Articulo.objects.all().order_by('-fecha')
return render(request, 'index.html', {'articulos':articulos})