{"id":379,"date":"2021-02-09T14:33:13","date_gmt":"2021-02-09T08:33:13","guid":{"rendered":"http:\/\/www.jichangqing.net\/wordpress\/?p=379"},"modified":"2021-02-09T18:51:22","modified_gmt":"2021-02-09T12:51:22","slug":"django%e6%94%af%e6%8c%81https-%e5%88%a9%e7%94%a8runserver_plus%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"http:\/\/www.jichangqing.net\/wordpress\/?p=379","title":{"rendered":"Django\u652f\u6301https&#8211;\u5229\u7528runserver_plus\u5b9e\u73b0+django by example\u7b2c\u4e94\u7ae0\u52d8\u8bef\u3002"},"content":{"rendered":"<p>\u4eca\u5929\u8c03\u8bd5django by example\u6559\u6750\u7b2c\u4e94\u7ae0\u00a0\u5728\u4f60\u7684\u7f51\u7ad9\u4e2d\u5206\u4eab\u5185\u5bb9\uff0c\u00a0\u5efa\u7acb\u4e00\u4e2a\u80fd\u4e3a\u56fe\u7247\u6253\u6807\u7b7e\u7684\u7f51\u7ad9\uff0c\u9047\u5230\uff0c\u53f3\u4e0a\u89d2\u91c7\u96c6\u56fe\u7247\u529f\u80fd\u51fa\u4e0d\u6765\uff0c\u67e5\u4e86\u4e00\u4e0b\u65b0\u7248\uff0c\u9700\u8981\u8fd0\u884c runserver_plus\uff0c\u6765\u652f\u6301https\u5b89\u5168\u534f\u8bae<\/p>\n<p>python manage.py runserver_plus &#8211;cert-file cert.crt<\/p>\n<p>\u4f46\u63d0\u793a\uff1a<\/p>\n<p>Unknown command: &#8216;runserver_plus&#8217;. Did you mean runserver?<br \/>\nType &#8216;manage.py help&#8217; for usage.<\/p>\n<p>\u4e8e\u662f\u7814\u7a76\u4e00\u4e0b\u5982\u4f55\u5b9e\u73b0https\u6765\u652f\u6301\u8bc1\u4e66\uff1a<\/p>\n<h2 style=\"font-weight: bold; color: #4f4f4f;\">1.python\u73af\u5883\u51c6\u5907<\/h2>\n<p style=\"color: #4d4d4d;\">\u786e\u8ba4\u4e4b\u524d\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5Python3\uff0cDjango1.8\u53ca\u4ee5\u4e0a<br \/>\n\u8fd8\u9700\u8981\u5b89\u88c5\u7684python\u5e93\u6709\uff1a<\/p>\n<pre class=\"prettyprint\" style=\"color: #000000;\"><code class=\"prism language-python has-numbering\" style=\"color: #abb2bf;\">\u6267\u884cpip install\u547d\u4ee4\u5b89\u88c5\r\npython3 <span class=\"token operator\" style=\"color: #669900;\">-<\/span>m pip install django<span class=\"token operator\" style=\"color: #669900;\">-<\/span>extensions\r\npython3 <span class=\"token operator\" style=\"color: #669900;\">-<\/span>m pip install django<span class=\"token operator\" style=\"color: #669900;\">-<\/span>werkzeug<span class=\"token operator\" style=\"color: #669900;\">-<\/span>debugger<span class=\"token operator\" style=\"color: #669900;\">-<\/span>runserver\r\npython3 <span class=\"token operator\" style=\"color: #669900;\">-<\/span>m pip install pyOpenSSL<\/code><\/pre>\n<h2 style=\"font-weight: bold; color: #4f4f4f;\">2.\u914d\u7f6esettings.py<\/h2>\n<p style=\"color: #4d4d4d;\">INSTALLED_APPS\u672b\u5c3e\u52a0\u5165\u4e0b\u9762\u51e0\u884c\uff0c\u5e76\u4fdd\u5b58<\/p>\n<pre class=\"prettyprint\" style=\"color: #000000;\"><code class=\"prism language-python has-numbering\" style=\"color: #abb2bf;\">  <span class=\"token string\" style=\"color: #669900;\">'werkzeug_debugger_runserver'<\/span><span class=\"token punctuation\" style=\"color: #999999;\">,<\/span>\r\n  <span class=\"token string\" style=\"color: #669900;\">'django_extensions'<\/span><span class=\"token punctuation\" style=\"color: #999999;\">,<\/span><\/code><\/pre>\n<h2 style=\"font-weight: bold; color: #4f4f4f;\">3.\u5f00\u542f\u670d\u52a1\uff0c\u4f7f\u7528runserver_plus\u66ff\u6362runserver<\/h2>\n<pre class=\"prettyprint\" style=\"color: #000000;\"><code class=\"prism language-bash has-numbering\" style=\"color: #abb2bf;\">  python manage.py runserver_plus --cert-file cert.crt<\/code><\/pre>\n<p>\u663e\u793a\uff1a<br \/>\n* Restarting with stat<br \/>\nPerforming system checks&#8230;<\/p>\n<p>System check identified no issues (0 silenced).<\/p>\n<p>Django version 3.1.5, using settings &#8216;bookmarks.settings&#8217;<br \/>\nDevelopment server is running at https:\/\/[127.0.0.1]:8000\/<br \/>\nUsing the Werkzeug debugger (http:\/\/werkzeug.pocoo.org\/)<br \/>\nQuit the server with CTRL-BREAK.<br \/>\n* Debugger is active!<br \/>\n* Debugger PIN: 688-013-692<br \/>\n* Running on https:\/\/127.0.0.1:8000\/ (Press CTRL+C to quit)<\/p>\n<p>=====<\/p>\n<p>\u672c\u4e66\u4e2d create.html\u00a0\u6539\u4e3a\uff1a<\/p>\n<pre>{% extends 'base.html' %}\r\n\r\n{% block title %}Bookmark an image{% endblock %}\r\n\r\n{% block content %}\r\n    &lt;<span style=\"color: #63a35c;\">h1<\/span>&gt;Bookmark an image&lt;\/<span style=\"color: #63a35c;\">h1<\/span>&gt;\r\n    &lt;<span style=\"color: #63a35c;\">img <\/span><span style=\"color: #795da3;\">src<\/span><span style=\"font-weight: bold; color: #183691;\">=\"{{ request.GET.url }}\" <\/span><span style=\"color: #795da3;\">class<\/span><span style=\"font-weight: bold; color: #183691;\">=\"image-preview\"<\/span>&gt;\r\n    &lt;<span style=\"color: #63a35c;\">form <\/span><span style=\"color: #795da3;\">action<\/span><span style=\"font-weight: bold; color: #183691;\">=\".\" <\/span><span style=\"color: #795da3;\">method<\/span><span style=\"font-weight: bold; color: #183691;\">=\"post\"<\/span>&gt;\r\n        {{ form.as_p }}\r\n        {% csrf_token %}\r\n        &lt;<span style=\"color: #63a35c;\">input <\/span><span style=\"color: #795da3;\">type<\/span><span style=\"font-weight: bold; color: #183691;\">=\"submit\" <\/span><span style=\"color: #795da3;\">value<\/span><span style=\"font-weight: bold; color: #183691;\">=\"Bookmark it!\"<\/span>&gt;\r\n    &lt;\/<span style=\"color: #63a35c;\">form<\/span>&gt;\r\n{% endblock %}<\/pre>\n<p>bookmarklet.js\u00a0\u5185\u5bb9\u6539\u4e3a\uff1a<\/p>\n<pre>(<span style=\"font-weight: bold; color: #000080;\">function<\/span>(){\r\n  <span style=\"font-weight: bold; color: #000080;\">var <\/span>jquery_version = <span style=\"font-weight: bold; color: #183691;\">'3.4.1'<\/span>;\r\n  <span style=\"font-weight: bold; color: #000080;\">var <\/span>site_url = <span style=\"font-weight: bold; color: #183691;\">'https:\/\/127.0.0.1:8000\/'<\/span>;\r\n  <span style=\"font-weight: bold; color: #000080;\">var <\/span>static_url = site_url + <span style=\"font-weight: bold; color: #183691;\">'static\/'<\/span>;\r\n  <span style=\"font-weight: bold; color: #000080;\">var <\/span>min_width = <span style=\"color: #0086b3;\">100<\/span>;\r\n  <span style=\"font-weight: bold; color: #000080;\">var <\/span>min_height = <span style=\"color: #0086b3;\">100<\/span>;\r\n\r\n  <span style=\"font-weight: bold; color: #000080;\">function <\/span>bookmarklet(msg) {\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ load CSS\r\n<\/span><span style=\"font-weight: bold; color: #000080;\">var <\/span>css = jQuery(<span style=\"font-weight: bold; color: #183691;\">'&lt;link&gt;'<\/span>);\r\n    css.attr({\r\n      rel: <span style=\"font-weight: bold; color: #183691;\">'stylesheet'<\/span>,\r\n      type: <span style=\"font-weight: bold; color: #183691;\">'text\/css'<\/span>,\r\n      href: static_url + <span style=\"font-weight: bold; color: #183691;\">'css\/bookmarklet.css?r=' <\/span>+ Math.floor(Math.random()*<span style=\"color: #0086b3;\">99999999999999999999<\/span>)\r\n    });\r\n    jQuery(<span style=\"font-weight: bold; color: #183691;\">'head'<\/span>).append(css);\r\n\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ load HTML\r\n<\/span>box_html = <span style=\"font-weight: bold; color: #183691;\">'&lt;div id=\"bookmarklet\"&gt;&lt;a href=\"#\" id=\"close\"&gt;&amp;times;&lt;\/a&gt;&lt;h1&gt;Select an image to bookmark:&lt;\/h1&gt;&lt;div class=\"images\"&gt;&lt;\/div&gt;&lt;\/div&gt;'<\/span>;\r\n    jQuery(<span style=\"font-weight: bold; color: #183691;\">'body'<\/span>).append(box_html);\r\n\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ close event\r\n<\/span>jQuery(<span style=\"font-weight: bold; color: #183691;\">'#bookmarklet #close'<\/span>).click(<span style=\"font-weight: bold; color: #000080;\">function<\/span>(){\r\n       jQuery(<span style=\"font-weight: bold; color: #183691;\">'#bookmarklet'<\/span>).remove();\r\n    });\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ find images and display them\r\n<\/span>jQuery.each(jQuery(<span style=\"font-weight: bold; color: #183691;\">'img[src$=\"jpg\"]'<\/span>), <span style=\"font-weight: bold; color: #000080;\">function<\/span>(index, image) {\r\n      <span style=\"font-weight: bold; color: #000080;\">if <\/span>(jQuery(image).width() &gt;= min_width &amp;&amp; jQuery(image).height()\r\n      &gt;= min_height)\r\n      {\r\n        image_url = jQuery(image).attr(<span style=\"font-weight: bold; color: #183691;\">'src'<\/span>);\r\n        jQuery(<span style=\"font-weight: bold; color: #183691;\">'#bookmarklet .images'<\/span>).append(<span style=\"font-weight: bold; color: #183691;\">'&lt;a href=\"#\"&gt;&lt;img src=\"'<\/span>+\r\n        image_url +<span style=\"font-weight: bold; color: #183691;\">'\" \/&gt;&lt;\/a&gt;'<\/span>);\r\n      }\r\n    });\r\n\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ when an image is selected open URL with it\r\n<\/span>jQuery(<span style=\"font-weight: bold; color: #183691;\">'#bookmarklet .images a'<\/span>).click(<span style=\"font-weight: bold; color: #000080;\">function<\/span>(e){\r\n      selected_image = jQuery(<span style=\"font-weight: bold; color: #000080;\">this<\/span>).children(<span style=\"font-weight: bold; color: #183691;\">'img'<\/span>).attr(<span style=\"font-weight: bold; color: #183691;\">'src'<\/span>);\r\n      <span style=\"font-style: italic; color: #969896;\">\/\/ hide bookmarklet\r\n<\/span>jQuery(<span style=\"font-weight: bold; color: #183691;\">'#bookmarklet'<\/span>).hide();\r\n      <span style=\"font-style: italic; color: #969896;\">\/\/ open new window to submit the image\r\n<\/span>window.open(site_url +<span style=\"font-weight: bold; color: #183691;\">'images\/create\/?url='\r\n<\/span>+ encodeURIComponent(selected_image)\r\n                  + <span style=\"font-weight: bold; color: #183691;\">'&amp;title='\r\n<\/span>+ encodeURIComponent(jQuery(<span style=\"font-weight: bold; color: #183691;\">'title'<\/span>).text()),\r\n                  <span style=\"font-weight: bold; color: #183691;\">'_blank'<\/span>);\r\n    });\r\n\r\n  };\r\n\r\n  <span style=\"font-style: italic; color: #969896;\">\/\/ Check if jQuery is loaded\r\n<\/span><span style=\"font-weight: bold; color: #000080;\">if<\/span>(<span style=\"font-weight: bold; color: #000080;\">typeof <\/span>window.jQuery != <span style=\"font-weight: bold; color: #183691;\">'undefined'<\/span>) {\r\n    bookmarklet();\r\n  } <span style=\"font-weight: bold; color: #000080;\">else <\/span>{\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ Check for conflicts\r\n<\/span><span style=\"font-weight: bold; color: #000080;\">var <\/span>conflict = <span style=\"font-weight: bold; color: #000080;\">typeof <\/span>window.$ != <span style=\"font-weight: bold; color: #183691;\">'undefined'<\/span>;\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ Create the script and point to Google API\r\n<\/span><span style=\"font-weight: bold; color: #000080;\">var <\/span>script = document.createElement(<span style=\"font-weight: bold; color: #183691;\">'script'<\/span>);\r\n    script.src = <span style=\"font-weight: bold; color: #183691;\">'\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/' <\/span>+\r\n      jquery_version + <span style=\"font-weight: bold; color: #183691;\">'\/jquery.min.js'<\/span>;\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ Add the script to the 'head' for processing\r\n<\/span>document.head.appendChild(script);\r\n    <span style=\"font-style: italic; color: #969896;\">\/\/ Create a way to wait until script loading\r\n<\/span><span style=\"font-weight: bold; color: #000080;\">var <\/span>attempts = <span style=\"color: #0086b3;\">15<\/span>;\r\n    (<span style=\"font-weight: bold; color: #000080;\">function<\/span>(){\r\n      <span style=\"font-style: italic; color: #969896;\">\/\/ Check again if jQuery is undefined\r\n<\/span><span style=\"font-weight: bold; color: #000080;\">if<\/span>(<span style=\"font-weight: bold; color: #000080;\">typeof <\/span>window.jQuery == <span style=\"font-weight: bold; color: #183691;\">'undefined'<\/span>) {\r\n        <span style=\"font-weight: bold; color: #000080;\">if<\/span>(--attempts &gt; <span style=\"color: #0086b3;\">0<\/span>) {\r\n          <span style=\"font-style: italic; color: #969896;\">\/\/ Calls himself in a few milliseconds\r\n<\/span>window.setTimeout(arguments.callee, <span style=\"color: #0086b3;\">250<\/span>)\r\n        } <span style=\"font-weight: bold; color: #000080;\">else <\/span>{\r\n          <span style=\"font-style: italic; color: #969896;\">\/\/ Too much attempts to load, send error\r\n<\/span>alert(<span style=\"font-weight: bold; color: #183691;\">'An error occurred while loading jQuery'<\/span>)\r\n        }\r\n      } <span style=\"font-weight: bold; color: #000080;\">else <\/span>{\r\n          bookmarklet();\r\n      }\r\n    })();\r\n  }\r\n})()<\/pre>\n<p>360\u6781\u901f\u6d4f\u89c8\u5668\uff0c\u70b9\u51fb\u5c0f\u76fe\u724c\uff0c\u540c\u610f\u811a\u672c\u8fd0\u884c\u3002<\/p>\n<p><a href=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/dunpai.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-387\" src=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/dunpai.jpg\" alt=\"dunpai\" width=\"367\" height=\"205\" srcset=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/dunpai.jpg 367w, http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/dunpai-300x167.jpg 300w\" sizes=\"auto, (max-width: 367px) 100vw, 367px\" \/><\/a><\/p>\n<p>\u6d4f\u89c8\u5668\u4ece\u6781\u901f\u6a21\u5f0f\u5207\u6362\u5230\u517c\u5bb9\u6a21\u5f0f\uff0c\u6253\u5f00www.amazon.com,\u51fa\u73b0\u5b89\u5168\u8b66\u62a5\uff0c\u9009\u662f<\/p>\n<p><a href=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/worning.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-380\" src=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/worning.jpg\" alt=\"worning\" width=\"456\" height=\"396\" srcset=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/worning.jpg 456w, http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/worning-300x260.jpg 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/a><br \/>\n\u6d4b\u8bd5\u6210\u529f<\/p>\n<p><a href=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/355.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-382 size-large\" src=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/355-1024x551.png\" alt=\"355\" width=\"1024\" height=\"551\" srcset=\"http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/355-1024x551.png 1024w, http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/355-300x161.png 300w, http:\/\/www.jichangqing.net\/wordpress\/wp-content\/uploads\/2021\/02\/355.png 1110w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u8c03\u8bd5django by example\u6559\u6750\u7b2c\u4e94\u7ae0\u00a0\u5728\u4f60\u7684\u7f51\u7ad9\u4e2d\u5206\u4eab\u5185\u5bb9\uff0c\u00a0\u5efa\u7acb\u4e00\u4e2a\u80fd\u4e3a\u56fe\u7247\u6253\u6807\u7b7e\u7684\u7f51\u7ad9\uff0c\u9047\u5230\uff0c\u53f3\u4e0a\u89d2\u91c7\u96c6\u56fe\u7247\u529f\u80fd\u51fa\u4e0d\u6765\uff0c\u67e5\u4e86\u4e00\u4e0b\u65b0\u7248\uff0c\u9700\u8981\u8fd0\u884c runserver_plus\uff0c\u6765\u652f\u6301https\u5b89\u5168\u534f\u8bae python man &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-379","post","type-post","status-publish","format-standard","hentry","category-django"],"_links":{"self":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=379"}],"version-history":[{"count":5,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/379\/revisions"}],"predecessor-version":[{"id":388,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/379\/revisions\/388"}],"wp:attachment":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}