{"id":444,"date":"2020-07-23T19:21:38","date_gmt":"2020-07-23T10:21:38","guid":{"rendered":"https:\/\/blog.hgrs.me\/?p=444"},"modified":"2020-07-23T19:21:38","modified_gmt":"2020-07-23T10:21:38","slug":"%e3%81%95%e3%81%8f%e3%82%89%e3%81%ae%e3%83%ac%e3%83%b3%e3%82%bf%e3%83%ab%e3%82%b5%e3%83%bc%e3%83%90%ef%bc%88%e3%82%b9%e3%82%bf%e3%83%b3%e3%83%80%e3%83%bc%e3%83%89%ef%bc%89%e3%81%a7-django-3-0","status":"publish","type":"post","link":"https:\/\/blog.hgrs.me\/archives\/444.html","title":{"rendered":"\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\uff08\u30b9\u30bf\u30f3\u30c0\u30fc\u30c9\uff09\u3067 Django 3.0 \u3092\u52d5\u304b\u3059\u65b9\u6cd5"},"content":{"rendered":"

\u306f\u3058\u3081\u306b<\/h2>\n

\u50d5\u306f\u30b5\u30fc\u30d0\u3092\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u306e\u30b9\u30bf\u30f3\u30c0\u30fc\u30c9\u30d7\u30e9\u30f3\u3057\u304b\u501f\u308a\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u3067\u30ac\u30b7\u30ac\u30b7\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u52d5\u304b\u3059\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u306e\u3067\u3059\u304c\u3001Django \u3092\u4f7f\u3063\u3066 API \u3092\u4f5c\u308a\u305f\u304b\u3063\u305f\u306e\u3067\u3001\u305d\u306e\u8a2d\u5b9a\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n

\u7d39\u4ecb\u3059\u308b\u7bc4\u56f2<\/h2>\n

\u4eca\u56de\u306f Django \u306e WSGI \u3092 CGI \u3092\u901a\u3057\u3066\u5229\u7528\u3059\u308b\u65b9\u6cd5\u306e\u307f\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n

\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u3067 Python \u81ea\u4f53\u3092\u5229\u7528\u3059\u308b\u65b9\u6cd5\u3084 Django \u306e\u7d30\u304b\u306a\u8a2d\u5b9a\u81ea\u4f53\u306f\u7d39\u4ecb\u3057\u307e\u305b\u3093\u3002<\/p>\n

CGI \u306e\u8a2d\u5b9a<\/h2>\n

\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u3067\u306f mod_wsgi<\/code> \u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u305f\u3081\u3001Python \u3092\u5b9f\u884c\u3059\u308b\u306b\u306f CGI \u3092\u901a\u3055\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u3002<\/p>\n

\u305d\u3053\u3067\u3001 Django \u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30eb\u30fc\u30c8\u306b index.cgi<\/code> \u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u66f8\u304d\u52a0\u3048\u307e\u3059\u3002
\n\u3053\u306e\u969b\u3001\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u3092 755<\/code> \u306b\u6307\u5b9a\u3059\u308b\u306e\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n

#!\/path\/to\/python\n\nimport sys\nsys.path.append('\/path\/to\/djangoproject\/')\n\nimport cgitb\ncgitb.enable()\n\nfrom wsgiref.handlers import CGIHandler\nfrom projectname.wsgi import application\n\nCGIHandler().run(application)<\/code><\/pre>\n

\u307e\u305a\u30011\u884c\u76ee\u306f\u4f7f\u7528\u3057\u3066\u3044\u308b Python \u306e\u74b0\u5883\u3092\u3057\u3066\u3057\u307e\u3059\u3002
\npyenv \u3068 pyenv-virtualenv \u306a\u3069\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306f #!\/home\/username\/.pyenv\/versions\/envname\/python<\/code> \u306a\u3069\u3067\u3059\u306d\u3002<\/p>\n

4\u884c\u76ee\u306f\u4eca\u4f7f\u7528\u3057\u3066\u3044\u308b Django \u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3078\u306e\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002
\n\u3053\u3053\u306f pwd<\/code> \u3067\u8868\u793a\u3055\u308c\u308b\u5024\u3092\u305d\u306e\u307e\u307e\u6301\u3063\u3066\u304f\u308c\u3070\u5927\u4e08\u592b\u3067\u3059\u3002<\/p>\n

10\u884c\u76ee\u306e projectname \u306f\u81ea\u5206\u3067\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n

\u5185\u90e8\u3067\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f Django \u304c\u8a2d\u5b9a\u3057\u3066\u3044\u308b WSGI \u3092 CGI \u30cf\u30f3\u30c9\u30e9\u30fc\u306b\u8f09\u305b\u3066\u5b9f\u884c\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n

\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u308b<\/h2>\n

index.cgi<\/code> \u3092\u5165\u308a\u53e3\u3068\u3057\u3066\u3044\u308b\u306e\u3067 https:\/\/example.com\/index.cgi<\/code> \u304c\u30eb\u30fc\u30c8\u306b\u306a\u308a\u307e\u3059\u3002
\n\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u7ba1\u7406\u753b\u9762\u3060\u3068 https:\/\/example.com\/index.cgi\/admin<\/code> \u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

\u30a2\u30af\u30bb\u30b9\u3059\u308b\u969b\u306b\u306f settings.py<\/code> \u306e ALLOWED_HOSTS<\/code> \u306b\u30db\u30b9\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u306e\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n

\u307e\u305f\u3053\u306e\u307e\u307e\u3060\u3068 index.cgi<\/code> \u304c\u5e38\u306b\u5165\u3063\u3066\u3044\u3066\u30c0\u30b5\u3044\u306e\u3067 .htaccess<\/code> \u3092\u7528\u3044\u3066 index.cgi<\/code> \u7121\u3057\u3067\u898b\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n

RewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule ^(.*)$ \/index.cgi\/$1 [QSA,L]<\/code><\/pre>\n

\u304a\u308f\u308a\u306b<\/h2>\n

\u4ee5\u4e0a\u3001\u7c21\u5358\u3067\u3057\u305f\u304c\u30b9\u30bf\u30f3\u30c0\u30fc\u30c9\u306e\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u3067 Django \u3092\u52d5\u304b\u3059\u65b9\u6cd5\u3067\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u306f\u3058\u3081\u306b \u50d5\u306f\u30b5\u30fc\u30d0\u3092\u3055\u304f\u3089\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u306e\u30b9\u30bf\u30f3\u30c0\u30fc\u30c9\u30d7\u30e9\u30f3\u3057\u304b\u501f\u308a\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u3067…<\/p>\n","protected":false},"author":1,"featured_media":445,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[41,14],"_links":{"self":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts\/444"}],"collection":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/comments?post=444"}],"version-history":[{"count":1,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts\/444\/revisions"}],"predecessor-version":[{"id":452,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/posts\/444\/revisions\/452"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/media\/445"}],"wp:attachment":[{"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/media?parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/categories?post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hgrs.me\/wp-json\/wp\/v2\/tags?post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}