{"id":355,"date":"2017-03-13T11:16:00","date_gmt":"2017-03-13T02:16:00","guid":{"rendered":""},"modified":"2022-03-15T14:21:15","modified_gmt":"2022-03-15T05:21:15","slug":"gaepython-27-django-15-sslcron-jobs301","status":"publish","type":"post","link":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/2017\/03\/gaepython-27-django-15-sslcron-jobs301.html","title":{"rendered":"GAE(Python 2.7) + Django 1.5 + SSL\u306ecron jobs\u3067301\u30a8\u30e9\u30fc"},"content":{"rendered":"<div data-post-id=\"1297\" class=\"insert-page insert-page-1297 \"><div class=\"st-kaiwa-box kaiwaicon3 clearfix\"><div class=\"st-kaiwa-face\"><img decoding=\"async\" src=\"http:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-content\/uploads\/sites\/2\/2022\/03\/profile.jpg\" width=\"60px\"><div class=\"st-kaiwa-face-name\">\u6587\u5b57\u5b9f<\/div><\/div><div class=\"st-kaiwa-area\"><div class=\"st-kaiwa-hukidashi\">\u3053\u306e\u8a18\u4e8b\u306f\u3001\u682a\u5f0f\u4f1a\u793e\u30b7\u30b0\u30de\u30fb\u30c7\u30b6\u30a4\u30f3\u793e\u9577\u306e<a href=\"https:\/\/www.sigmadesign.co.jp\/president\/\" target=\"_blank\" rel=\"noopener\">\u6587\u5b57\u5b9f<\/a>\u304c\u57f7\u7b46\u3057\u307e\u3057\u305f\u3002<\/div><\/div><\/div>\n<\/div>\n<p>\u72ec\u81ea\u30c9\u30e1\u30a4\u30f3\u3092\u4f7f\u3063\u3066Google App Engine\u3067\u904b\u7528\u3057\u3066\u3044\u308b\u30b5\u30a4\u30c8\u304c\u3042\u3063\u3066\u3001cron\u304c\u3046\u307e\u304f\u52d5\u304b\u305a\u306b\u304b\u306a\u308a\u30cf\u30de\u308a\u307e\u3057\u305f\u3002\u306a\u3093\u3068\u304b\u89e3\u6c7a\u3067\u304d\u305f\u306e\u3067\u3001\u79c1\u304c\u3084\u3063\u305f\u89e3\u6c7a\u6cd5\u3092\u66f8\u3044\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u540c\u3058\u3088\u3046\u306a\u75c7\u72b6\u3067\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u3044\u308b\u4eba\u306f\u3042\u307e\u308a\u3044\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3082\u3057\u5f53\u3066\u306f\u307e\u3063\u305f\u3089\u53c2\u8003\u306b\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<p>\u74b0\u5883\u306f\u3060\u3044\u305f\u3044\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3002<\/p>\n<ul>\n<li>Google App Engine<\/li>\n<li>Python 2.7<\/li>\n<li>\u72ec\u81ea\u30c9\u30e1\u30a4\u30f3\uff08\u30ab\u30b9\u30bf\u30e0\u30c9\u30e1\u30a4\u30f3\uff09\u3067\u904b\u7528<\/li>\n<li>SSL\u5bfe\u5fdc<\/li>\n<li>Django 1.5<\/li>\n<\/ul>\n<p>\u8a2d\u5b9a\u306f\u3046\u307e\u304f\u3067\u304d\u3066\u308b\u306f\u305a\u306a\u306e\u306bcron jobs\u304c\u8d77\u52d5\u3059\u308b\u3068\u5931\u6557\u3059\u308b\u3068\u3044\u3046\u75c7\u72b6\u304c\u51fa\u307e\u3057\u305f\u3002<\/p>\n<p>\u30d6\u30e9\u30a6\u30b6\u3067\u76f4\u63a5URL\u3092\u5165\u529b\u3059\u308b\u3068\u554f\u984c\u306a\u304f\u52d5\u3044\u3066\u3044\u308b\u306e\u306b\u3001cron\u3067\u52d5\u304b\u3059\u3068\u306a\u305c\u304b\u5931\u6557\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u30ed\u30b0\u3092\u8abf\u3079\u3066\u307f\u308b\u3068cron\u3067\u306e\u30a2\u30af\u30bb\u30b9\u306eHTTP\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u304c301\u306b\u306a\u3063\u3066\u3044\u308b\u3002\u4ed6\u65b9\u3067\u30d6\u30e9\u30a6\u30b6\u3067URL\u3092\u5165\u529b\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3057\u305f\u5834\u5408\u306b\u306f200\u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>GAE\u306ecron jobs\u306f\u3001HTTP\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3092200\u756a\u53f0\u3067\u8fd4\u3055\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u77e5\u3063\u3066\u305f\u306e\u3067\u3001301\u304c\u8fd4\u3063\u3066\u304d\u3066\u3044\u308b\u4ee5\u4e0a\u306f\u5931\u6557\u3059\u308b\u3068\u3044\u3046\u306e\u306f\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u3082\u3001\u306a\u305c301\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306b\u306a\u308b\u306e\u304b\u304c\u5168\u304f\u5206\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>\u304b\u306a\u308a\u82e6\u52b4\u3057\u3066\u5206\u304b\u3063\u305f\u539f\u56e0\u306f\u3001Django\u306esettings.py\u306eMIDDLEWARE_CLASSES\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u305fSSLRedirect\u306e\u8a2d\u5b9a\u3067\u3057\u305f\u3002<\/p>\n<p>\u305d\u3093\u306a\u8a2d\u5b9a\u3092\u3057\u3066\u305f\u306e\u3092\u3059\u3063\u304b\u308a\u5fd8\u308c\u3066\u305f\u3051\u3069\u3001\u30b0\u30fc\u30b0\u30eb\u304c\u5168\u3066\u306e\u30b5\u30a4\u30c8\u3067SSL\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u3092\u63a8\u5968\u3057\u59cb\u3081\u305f\u6570\u5e74\u524d\u306b\u81ea\u5206\u3067\u8a2d\u5b9a\u3057\u3066\u305f\u306e\u3067\u3059\u3002<\/p>\n<p>\u305b\u3063\u304b\u304fSSL\u5bfe\u5fdc\u3057\u305f\u306e\u3060\u304b\u3089\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u305f\u3081\u3068SEO\u306e\u305f\u3081\u306bhttp\u306b\u6765\u305f\u30a2\u30af\u30bb\u30b9\u3092\u81ea\u52d5\u3067\u5168\u3066https\u306b301\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u305f\u3081\u306b\u3001sslmiddleware\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u305f\u306e\u3067\u3059\u3002<\/p>\n<p>\u53c2\u8003URL<\/p>\n<ul>\n<li><a href=\"http:\/\/memo.saitodev.com\/home\/python_django\/\" target=\"_blank\" rel=\"noopener\">http:\/\/memo.saitodev.com\/home\/python_django\/<\/a><\/li>\n<li><a href=\"https:\/\/djangosnippets.org\/snippets\/85\/\" target=\"_blank\" rel=\"noopener\">https:\/\/djangosnippets.org\/snippets\/85\/<\/a><\/li>\n<\/ul>\n<p>\u5177\u4f53\u7684\u306b\u306fDjango\u306esettings.py\u306e\u3053\u306e\u90e8\u5206\u3067\u3059\u3002<\/p>\n<div style=\"background-color: lightgray; padding: 10px;\">\n<pre><code>\r\nMIDDLEWARE_CLASSES = (\r\n    .........\r\n    .........\r\n    'appname.middles.sslmiddleware.SSLRedirect',\r\n)\r\n<\/code><\/pre>\n<\/div>\n<p>cron.yaml\u306b\u30bf\u30fc\u30b2\u30c3\u30c8\u3092\u8a2d\u5b9a\u3092\u3057\u3066\u306a\u3044\u5834\u5408\u3001cron\u304c\u8d77\u52d5\u3059\u308b\u3068\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306eURL\u306b\u30a2\u30af\u30bb\u30b9\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u3044\u3046\u306e\u306f\u3001\u30ed\u30b0\u3092\u898b\u3066\u307f\u308b\u3068\u72ec\u81ea\u30c9\u30e1\u30a4\u30f3\u3067\u904b\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u3067\u3082\u3001\u6700\u521d\u306b\u4e0e\u3048\u3089\u308c\u308b\u30c9\u30e1\u30a4\u30f3\u3067\u3042\u308bappspot.com\u306e\u65b9\u3067\u3059\u3002<\/p>\n<p>\u3057\u304b\u3082\u3001https\u3067\u306f\u306a\u304f\u3001http\u306e\u65b9\u306b\u30a2\u30af\u30bb\u30b9\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u8a2d\u5b9a\u3067\u72ec\u81ea\u30c9\u30e1\u30a4\u30f3\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u3002<\/p>\n<ol>\n<li>\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30c9\u30e1\u30a4\u30f3(http) -&gt; http:\/\/appname.appspot.com\/<\/li>\n<li>\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30c9\u30e1\u30a4\u30f3(https) -&gt; https:\/\/appname.appspot.com\/<\/li>\n<li>\u72ec\u81ea\u30c9\u30e1\u30a4\u30f3(http) -&gt; http:\/\/www.appname.com\/<\/li>\n<li>\u72ec\u81ea\u30c9\u30e1\u30a4\u30f3(https) -&gt; https:\/\/www.appname.com\/<\/li>\n<\/ol>\n<p>1\u30682\u306f\u6700\u521d\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u4e0e\u3048\u3089\u308c\u308b\u30c9\u30e1\u30a4\u30f3\u3067\u3001http\u3067\u3082https\u3067\u3082\u3069\u3061\u3089\u3067\u3082\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u79c1\u306e\u5834\u5408\u306f\u305d\u308c\u306b\u72ec\u81ea\u30c9\u30e1\u30a4\u30f3\u3092\u8a2d\u5b9a\u3057\u3066\u3001SSL\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u306e\u30674\u3092\u4e2d\u5fc3\u306b\u904b\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5148\u307b\u3069\u306esslmiddleware\u3092\u4f7f\u3063\u3066\u30013\u306ehttp\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3092\u5168\u3066\u81ea\u52d5\u7684\u306b4\u306ehttps\u306e\u65b9\u306b301\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u69d8\u306a\u8a2d\u5b9a\u306e\u72b6\u614b\u306e\u6642\u306bcron\u304c\u8d77\u52d5\u3059\u308b\u3068\u30011\u306e\u6307\u5b9a\u3057\u305f\u30d1\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068sslmiddleware\u306b\u3088\u3063\u3066\u81ea\u52d5\u7684\u306b2\u306ehttps\u306e\u65b9\u306b301\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3046\u306e\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u304c\u539f\u56e0\u3067\u3001cron\u304c\u5931\u6557\u3057\u3066\u3044\u305f\u306e\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306b\u306f\u3001cron\u3067\u8d77\u52d5\u3059\u308b\u30d1\u30b9\u306b\u5bfe\u3057\u3066\u3060\u3051301\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u3055\u305b\u306a\u3044\u3068\u3044\u3046\u8a2d\u5b9a\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>urls.py\u306bcron\u3067\u8d77\u52d5\u3055\u305b\u308b\u30d1\u30b9\u3092\u8a18\u8ff0\u3057\u3066\u3001\u65b0\u305f\u306b\u5225\u306essl_urls.py\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u4f5c\u3063\u3066\u6b8b\u308a\u3092\u5168\u3066\u5206\u96e2\u3057\u3066\u305d\u3061\u3089\u306b\u79fb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u5206\u96e2\u3057\u305fssl_urls.py\u3092include\u3067\u547c\u3073\u51fa\u3057\u3001\u305d\u308c\u306b{&#8216;SSL&#8217;:True}\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u308c\u3067cron\u3067\u8d77\u52d5\u3055\u305b\u308b\u30d1\u30b9\u306b\u5bfe\u3057\u3066\u306f301\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u751f\u3058\u305a\u306b\u3001\u305d\u308c\u4ee5\u5916\u306e\u30d1\u30b9\u306b\u5bfe\u3057\u3066\u306f301\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u304c\u751f\u3058\u308b\u3068\u3044\u3046\u8a2d\u5b9a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3088\u3046\u3084\u304fcron\u3067\u52d5\u304b\u3057\u3066\u3082200\u304c\u8fd4\u3063\u3066\u304d\u3066\u7121\u4e8b\u306b\u52d5\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>urls.py\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<div style=\"background-color: lightgray; padding: 10px;\">\n<pre><code>\r\nurlpatterns = patterns('',\r\n    # Cron\r\n    (r'^cron\/example\/$', cron_example),\r\n    (r'^cron\/........),\r\n                       \r\n    # SSL\r\n    (r'^.*?', include(appname.ssl_urls), {'SSL':True}),\r\n)\r\n<\/code><\/pre>\n<\/div>\n<p>\u6ce8\u610f\u304c\u5fc5\u8981\u306a\u306e\u306f\u300cr&#8217;^.*?&#8217;,\u300d\u306e\u90e8\u5206\u3067\u3059\u3002\u6700\u5f8c\u306b$\u304c\u8981\u308a\u307e\u305b\u3093\u3002\u6700\u5f8c\u306b$\u3092\u3064\u3051\u308b\u3068\u3069\u3053\u306e\u30d1\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3082\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u3044\u3046\u304a\u304b\u3057\u306a\u4e8b\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u7d50\u5c40\u3001\u3059\u3054\u304f\u7c21\u5358\u3067\u5358\u7d14\u306a\u4e8b\u304c\u539f\u56e0\u3060\u3063\u305f\u306e\u3067\u3001\u540c\u3058\u3088\u3046\u306a\u5931\u6557\u3092\u3057\u3066\u3044\u308b\u4eba\u306f\u307b\u3068\u3093\u3069\u3044\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u4e0b\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u5b57\u5b9f\u3053\u306e\u8a18\u4e8b\u306f\u3001\u682a\u5f0f\u4f1a\u793e\u30b7\u30b0\u30de\u30fb\u30c7\u30b6\u30a4\u30f3\u793e\u9577\u306e\u6587\u5b57\u5b9f\u304c\u57f7\u7b46\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":588,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[53,51],"class_list":["post-355","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-django","tag-gae"],"_links":{"self":[{"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/posts\/355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/comments?post=355"}],"version-history":[{"count":0,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/posts\/355\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/media\/588"}],"wp:attachment":[{"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/media?parent=355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/categories?post=355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sigmadesign.co.jp\/minomonchan\/wp-json\/wp\/v2\/tags?post=355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}