Django CSFR token missing or incorrect problem will you using forms

Django CSFR token missing or incorrect problem will you using forms. Possible ways to resolve this problem are:

1. add {% csrf_token %} in your form content and it will be converted into a hidden field in the form. Once you check the source code of the form you will see it.



{% extends "base.html" %}

{% block title %}Create Event - {{block.super}}{% endblock %}
{% block main_content %}
   
        {% csrf_token %}
       

                {{form.as_ul}}
           

       

   
{% endblock%}



Source cod ein the web browser:



   
        Create Event - start the dark
       
   
   
       
   
       

       

               
  • Description:


  •        

       

   

       
   


2. The other way to solve the problem is: comment  the following setence in your Django configure file.It solves the problem however, this is the very bad way to do it since you will lose CSRF protection by doing so.
 #'django.middleware.csrf.CsrfViewMiddleware'


Source: http://joelklabo.wordpress.com/2010/06/09/more-django-csrf-token-fun/

No comments:

Post a Comment

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...