Django app接口url报错Forbidden (CSRF cookie not set.)

这是因为Django对表单post请求做的安全性验证,在app开发中,可以干掉这一项,具体操作如下:

修改settings.py文件,注释掉
django.middleware.csrf.CsrfViewMiddleware'
MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

如上,就再也不会报错了

你可能感兴趣的:(python,django,csrf,form表单)