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">&times;</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>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/943e0bf4-ce4d-4ef5-ae45-57e86c36f367%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to