I want to post a form in my django project resulting in a "CSRF cookie not set." error.
views.py
from django.shortcuts import render
from django.template import RequestContext
from pyBikeMilesApp.models import Eintrag
from django.template.context_processors import csrf
# Create your views here.
def index(request):
if request.method == 'POST':
print(request.POST)
# Get all posts from DB
eintraege = Eintrag.objects
return render(request,'index.html',{'Eintraege': eintraege})
index.html
{% extends 'base.html' %}
{% block title %}BikeMiles{% endblock %}
{% block content %}
<div class="col-md-12">
<table class="table table-striped">
<tr>
<th>gefahrene KM</th>
<th>Datum</th>
<th>Kommentar</th>
<th>Aktion</th>
{% for eintrag in Eintraege %}
<tr>
<td>{{ eintrag.kommentar }}</td>
<form method="post" action="http://127.0.0.1:8000/">
{% csrf_token %}
<input type="hidden" name="id" value="{{eintrag.id}}">
<input type="submit" class="btn btn-xs btn-danger" value="delete" >
</form>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
in the generated page i can see the csrf input field:
<input type='hidden' name='csrfmiddlewaretoken' value='zzRnENjz6wrUP8Op8IVOIDsUVvclY37k' />
Any idea, how to fix that?