Hello
I am new to django I am trying to use modal (bootstrap) for embed by login form. I am using the following error. I have mentioned my code below and tried lot of googling... still no use.
Help
Reason given for failure:
CSRF token missing or incorrect.
Here is code in view.py
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.core.context_processors import csrf
from django.template import RequestContext
from django.views.decorators.csrf import csrf_protect
from django.shortcuts import render
@csrf_protect
def login(request):
c={}
c.update(csrf(request))
return render_to_response('login.html',c,context_instance=RequestContext(request))
I call the login.html via link in nav bar using
<li><a href="/accounts/login/" data-toggle="modal" data-target="#myModal">Login</a></li>
That is code for login.html which is modal included in my base.html
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<form action='/accounts/auth/' method='post'>{% csrf_token %}
<label for="username">User Name:</label>
<input type="text" name="username" value="" id="username">
<label for="password">Password:</label>
<input type="password" name="password" value="" id="password">
<input type="Submit" value="login" class="btn btn-primary">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>