Thursday, June 26, 2014

django user authenication form in modal form twitter bootstrap


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.


Reason given for failure:

    CSRF token missing or incorrect.    

Here is code in 

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

def login(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 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">
            <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>

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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment