jQuery: setting up CSRF token for Django not working

后端 未结 2 1380
梦如初夏
梦如初夏 2020-12-12 01:44

my jQuery function looks like

$(function() {
    // activate \"New\" buttons if input is not empty
    $(\'form input[type=\"text\"]\').live(\'k         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 02:23

    Above is the markup outputted by django. You want to grab the value of SOME_TOKEN. You will not be able to get it using the django template engine mixed with javascript since it will already be rendered into the input hidden.

    I would wrap my {{ csrf_token }} in a span/div and then use jquery to locate that span/div and grab the value of the input inside the span/div.

提交回复
热议问题