网页报错:
Access to XMLHttpRequest at 'http://www.millionsunshine.com/upload_goods' from origin 'http://millionsunshine.com' has been blocked by CORS policy: Request header field if-modified-since is not allowed by Access-Control-Allow-Headers in preflight response.
解决办法:
第一步,参照下面的文章配置好django,然后第二步.
https://blog.youkuaiyun.com/larger5/article/details/81265339
第二步,
在django的setting.py中增加下面标红的一行
CORS_ALLOW_HEADERS = (
'XMLHttpRequest',
'X_FILENAME',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
'Pragma',
'if-modified-since',#add to fix
)
问题解决了!
举一反三,如果是类似的问题,也可以把报错的header中的field加入进来,正如'if-modified-since'字段一样.
原因在于第一步中的文章并没有覆盖所有情形,有的字段没加入完全.