I've inherited a Django webapp that I need to add a basic file upload form to. The app is using Jinja for it's template engine. The first attempt of my upload template has a basic form like this:
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
<input type="file" name="datafile"></p>
<div><input type="submit" value="Upload"></div></form>
I've added 'django.middleware.csrf.CsrfViewMiddleware'
to my MIDDLEWARE_CLASSES list and I'm using RequestContext in my upload view.
If I try to access my upload page I get this error in my app's debug ouput:
Encountered unknown tag 'csrf_token'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.
After doing a little research I found the post here and changed my form to look like this
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<input type="file" name="datafile"></p>
<div><input type="submit" value="Upload"></div></form>
However, that takes me back to the 403 Forbidden page with a CSRF token missing or incorrect
in my debug output.
Any ideas what I need to do to get a csrf token playing nicely with jinja?