{"id":1520,"date":"2022-01-01T07:05:36","date_gmt":"2021-12-31T22:05:36","guid":{"rendered":"http:\/\/ts-engine.net\/?p=1520"},"modified":"2022-01-01T07:05:36","modified_gmt":"2021-12-31T22:05:36","slug":"javascript%e3%81%aecors%e3%82%a8%e3%83%a9%e3%83%bc%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6%e3%80%80django%e3%81%ae%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/ts-engine.net\/?p=1520","title":{"rendered":"javascript\u306eCORS\u30a8\u30e9\u30fc\u306b\u3064\u3044\u3066\u3000Django\u306e\u89e3\u6c7a\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u3092\u958b\u767a\u3059\u308b\u969b\u306b\u3001\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306fOctober CMS\u3084\u3001Python\u306eFast API\u3092\u4f7f\u3063\u3066\u3001\u30b9\u30de\u30db\u5074\u3092dart\u3084javascript\u3067\u66f8\u304f\u3001\u3068\u3044\u3046\u3053\u3068\u306e\u306f\u7d50\u69cb\u3042\u308b\uff0e<\/p>\n\n\n\n<p>\u30b9\u30de\u30db\u306e\u958b\u767a\u306f\u7d42\u308f\u3063\u305f\u304c\u3001\u305d\u306e\u5f8cWeb\u3082\u3084\u3063\u3071\u308a\u4f5c\u308a\u305f\u3044\u3068\u3044\u3046\u8981\u4ef6\u304c\u3042\u3063\u305f\u3068\u304d\u306b\u3001\u307e\u3042\u4e00\u822c\u7684\u306b\u306f\u9006\u3060\u304c\u3001\u305d\u306e\u3068\u304d\u306b\u540c\u3058\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3092\u4f7f\u3063\u3066\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3060\u3051React\u306a\u3069\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u958b\u767a\u3059\u308b\u3060\u3051\u306b\u3057\u3088\u3046\u3068\u3044\u3046\u306e\u306f\u4e00\u822c\u7684\u306a\u767a\u60f3\u3060\u3068\u601d\u3046\u3002<\/p>\n\n\n\n<p>\u305f\u3060\u3001\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u308b\u3068\u82e6\u52b4\u3059\u308b\u90e8\u5206\u304c\u3042\u308b\u306e\u3067\u4ee5\u4e0b\u306e\u901a\u308a\u307e\u3068\u3081\u308b\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">React Native\u306eAxios\u304b\u3089API\u3092\u8aad\u3093\u3067\u3082CORS\u30a8\u30e9\u30fc\u306b\u306a\u3089\u306a\u3044\u304cReact\u306eAxios\u304b\u3089\u3060\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3002<\/h2>\n\n\n\n<p>\u30a8\u30e9\u30fc\u5185\u5bb9\u306f\u3053\u306e\u3088\u3046\u306a\u611f\u3058\u3002<\/p>\n\n\n\n<p>from origin &#8216;http:\/\/localhost:3000&#8217; has been blocked by CORS policy: Response to preflight request doesn&#8217;t pass access control check: No &#8216;Access-Control-Allow-Origin&#8217; header is present on the requested resource.<\/p>\n\n\n\n<p>\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\u5074\u306eWebkit\u306b\u306f\u304a\u305d\u3089\u304fCORS\u306e\u30c1\u30a7\u30c3\u30af\u304c\u53b3\u3057\u304f\u306a\u3044\u3002<\/p>\n\n\n\n<p>\u4e00\u65b9\u3067PC\u306e\u30d6\u30e9\u30a6\u30b6\u306fCORS\u304c\u304b\u306a\u308a\u53b3\u3057\u304f\u30c1\u30a7\u30c3\u30af\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u305f\u3081\u3001\u540c\u3058\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3001\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u3082\u767a\u751f\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u306b\u306f\u3001\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306eAPI\u5074\u3067\u5bfe\u5fdc\u3059\u308b\u3057\u304b\u306a\u3044\u3002<\/p>\n\n\n\n<p>\u79c1\u306fDjango\u306eAPI\u30b5\u30fc\u30d0\u3092\u3042\u308b\u74b0\u5883\u3067\u4f5c\u3063\u3066\u3044\u308b\u306e\u3067\u691c\u8a3c\u3057\u3066\u307f\u305f\u3089\u3001Web\u304b\u3089\u306eAPI\u306b\u5fdc\u7b54\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u8a2d\u5b9a\u304c\u5fc5\u8981\u306b\u306a\u3063\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Django\u306eCORS\u5bfe\u7b56<\/h2>\n\n\n\n<p>\u307e\u305a\u306f\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002<\/p>\n\n\n\n<p>pip3 install django-cors-headers<\/p>\n\n\n\n<p>\u305d\u306e\u3054\u3001\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u6709\u52b9\u5316<\/p>\n\n\n\n<p>settings.py\u306b\u3066\u3001INSTALLED_APPS\u306e\u7b87\u6240\u3067\u3001<\/p>\n\n\n\n<p>&#8220;corsheaders&#8221;<\/p>\n\n\n\n<p>MIDDLEWARE\u306e\u7b87\u6240\u3067\u3001<\/p>\n\n\n\n<p>&#8220;corsheaders.middleware.CorsMiddleware&#8221;<\/p>\n\n\n\n<p>&#8220;django.middleware.common.CommonMiddleware&#8221;<\/p>\n\n\n\n<p>\u3092\u8ffd\u8a18\u3002<\/p>\n\n\n\n<p>\u66f4\u306b\u3001CORS\u306e\u30db\u30ef\u30a4\u30c8\u30ea\u30b9\u30c8\u3092\u8ffd\u8a18<\/p>\n\n\n\n<p>CORS_ALLOW_HEADERS = [&#8220;*&#8221;]<\/p>\n\n\n\n<p> CORS_ALLOW_ALL_ORIGINS = True<\/p>\n\n\n\n<p> CORS_ALLOW_CREDENTIALS = True<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u3053\u308c\u3067\u30b9\u30de\u30db\u304b\u3089\u3082\u30a2\u30d7\u30ea\u304b\u3089\u3082API\u306e\u30a2\u30af\u30bb\u30b9\u304c\u53ef\u80fd\u306b\u306a\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u3092\u958b\u767a\u3059\u308b\u969b\u306b\u3001\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306fOctober CMS\u3084\u3001Python\u306eFast API\u3092\u4f7f\u3063\u3066\u3001\u30b9\u30de\u30db\u5074\u3092dart\u3084javascript\u3067\u66f8\u304f\u3001\u3068\u3044\u3046\u3053\u3068\u306e\u306f\u7d50\u69cb\u3042\u308b\uff0e \u30b9\u30de\u30db\u306e\u958b\u767a\u306f\u7d42\u308f\u3063\u305f\u304c\u3001\u305d\u306e\u5f8cWeb\u3082\u3084\u3063\u3071\u308a\u4f5c\u308a\u305f\u3044\u3068\u3044\u3046\u8981\u4ef6\u304c\u3042\u3063\u305f\u3068\u304d\u306b\u3001\u307e\u3042\u4e00\u822c\u7684\u306b\u306f\u9006\u3060\u304c\u3001\u305d\u306e\u3068\u304d\u306b\u540c\u3058\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3092\u4f7f\u3063\u3066\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3060\u3051React\u306a\u3069\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u958b\u767a\u3059\u308b\u3060\u3051\u306b\u3057\u3088\u3046\u3068\u3044\u3046\u306e\u306f\u4e00\u822c\u7684\u306a\u767a\u60f3\u3060\u3068\u601d\u3046\u3002 \u305f\u3060\u3001\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u308b\u3068\u82e6\u52b4\u3059\u308b\u90e8\u5206\u304c\u3042\u308b\u306e\u3067\u4ee5\u4e0b\u306e\u901a\u308a\u307e\u3068\u3081\u308b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,6,16],"tags":[],"class_list":["post-1520","post","type-post","status-publish","format-standard","hentry","category-20","category-6","category-16"],"_links":{"self":[{"href":"http:\/\/ts-engine.net\/index.php?rest_route=\/wp\/v2\/posts\/1520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ts-engine.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ts-engine.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ts-engine.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ts-engine.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1520"}],"version-history":[{"count":0,"href":"http:\/\/ts-engine.net\/index.php?rest_route=\/wp\/v2\/posts\/1520\/revisions"}],"wp:attachment":[{"href":"http:\/\/ts-engine.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ts-engine.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1520"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ts-engine.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}