How do I include Django 1.2's CSRF token in a Javascript-generated HTML form?

前端 未结 6 1705
感动是毒
感动是毒 2020-12-09 05:45

I recently upgraded to Django 1.2.3 and my upload forms are now broken. Whenever I attempt to upload, I receive a \"CSRF verification failed. Request aborted.\" error messag

6条回答
  •  我在风中等你
    2020-12-09 06:23

    The easiest way is to create a hidden form on your page using django that doesn't do anything. Then use JavaScript to fetch the form and specifically the token input out of the form. Lastly, insert or copy that token input into the form you are dynamically generating.

    Here are two examples of how you might publish the token for JavaScript.

    
    
    
    

    or

    
    

提交回复
热议问题