python报错记录

python错误

================================================================================================================

django

   1.Forbidden (CSRF token missing or incorrect.):

    若是form表单中使用{%csrf_token%}

      若是ajax请求需要引入js

  $(function () {
    $.ajaxSetup({
        headers: { "X-CSRFToken": getCookie("csrftoken") }
    });
});
<!--getCookie函数:-->
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

    if(arr=document.cookie.match(reg))

        return unescape(arr[2]);
    else
        return null;
}

 Flask

  1.KeyError: 'A secret key is required to use CSRF.'

1.生成一个字符串

import uuid
uuid.uuid4().hex

2.添加

app.config["SECRET_KEY"] = 'd97073f46b214e9e9d890c41af49886e'

3.在页面引用

{{ form.csrf_token }}
原文地址:https://www.cnblogs.com/jokerq/p/8848495.html