{"id":42017,"date":"2023-06-24T21:58:42","date_gmt":"2022-12-11T20:59:47","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/"},"modified":"2024-04-30T10:32:23","modified_gmt":"2024-04-30T02:32:23","slug":"%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/","title":{"rendered":"\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f"},"content":{"rendered":"<h1>\u9996\u5148<\/h1>\n<p>\u4ee5\u4e0b\u662f\u5728IBM Cloud\u7684Virtual Private Cloud\uff08VPC\uff09\u7684\u865a\u62df\u5b9e\u4f8b\u4e2d\u542f\u52a8Python\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6Django\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u6b65\u9aa4\u3002\u867d\u7136Django\u672c\u8eab\u5df2\u7ecf\u4e0d\u662f\u4ec0\u4e48\u65b0\u9c9c\u4e8b\u7269\u4e86\uff0c\u4f46\u5f53\u8981\u8bc4\u4f30\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u6211\u4f1a\u91cd\u65b0\u6d4b\u8bd5\u5e76\u53d1\u5e03\u51fa\u80fd\u591f\u7acb\u5373\u4f7f\u7528\u8be5\u7248\u672c\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u5728\u8fd9\u6b21\u4e2d\uff0c\u6211\u4eec\u5c06\u5728VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaWeb\u670d\u52a1\u5668\u548c\u6570\u636e\u5e93\u670d\u52a1\u5668\uff0c\u7136\u540e\u90e8\u7f72\u4e00\u4e2a&#8221;\u7b80\u5355\u7684\u6295\u7968\uff08poll\uff09\u5e94\u7528\u7a0b\u5e8f&#8221;\uff0c\u5e76\u8fdb\u884cDjango\u7684\u7b2c\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u521b\u5efa\uff0c\u4ee5\u786e\u8ba4\u5176\u8fd0\u884c\u60c5\u51b5\u3002<\/p>\n<h1>\u7cfb\u7edf\u914d\u7f6e<\/h1>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d49ee37434c4406cb1598\/4-0.png\" alt=\"\u30b7\u30b9\u30c6\u30e0\u69cb\u6210\u56f3\" \/><\/div>\n<p>\u89d2\u8272<\/p>\n<p>\u4eee\u60f3\u30a4\u30f3\u30b9\u30bf\u30f3\u30b91(\u5916\u90e8\u30a2\u30af\u30bb\u30b9\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u53ef\u80fd)<\/p>\n<p>Web\u30b5\u30fc\u30d0<\/p>\n<p>OS: Ubuntu 20.04<br \/>\nWeb\u30b5\u30fc\u30d0 : Django\u306erunserver<br \/>\nPython : 3.8.5<br \/>\nDjango : 4.0.7<\/p>\n<p>\u4eee\u60f3\u30a4\u30f3\u30b9\u30bf\u30f3\u30b92(\u5916\u90e8\u30a2\u30af\u30bb\u30b9\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u4e0d\u53ef)<\/p>\n<p>DB\u30b5\u30fc\u30d0<\/p>\n<p>OS: Ubuntu 20.04<br \/>\nPostgreSQL : 12<\/p>\n<p>\u6211\u4eec\u6839\u636e\u4e0b\u9762\u7684Qiita\u6587\u7ae0\u53c2\u8003\uff0c\u521b\u5efa\u4e86\u865a\u62df\u79c1\u6709\u4e91\uff08VPC\uff09\u548c\u865a\u62df\u5b9e\u4f8b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h1>3. \u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u7684\u5f62\u8c61<\/h1>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d49ee37434c4406cb1598\/10-0.png\" alt=\"\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30a4\u30e1\u30fc\u30b8\" \/><\/div>\n<h1>4. \u6784\u5efa\u7a0b\u5e8f<\/h1>\n<h2>Ubuntu\u7684\u521d\u59cb\u8bbe\u7f6e\u3002<\/h2>\n<ul class=\"post-ul\">Web\u30b5\u30fc\u30d0\u30fbDB\u30b5\u30fc\u30d0\u5171\u901a\u4f5c\u696d<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8fdc\u7a0b\u670d\u52a1\u5668\u767b\u5f55<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u9996\u5148\u8981\u767b\u5f55\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u203b\u5728\u5ba2\u6237\u7aef\u8fdb\u884c\u64cd\u4f5c<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>ssh -i [\u79c1\u94a5\u6587\u4ef6\u540d] root@[WEB\u670d\u52a1\u5668\u7684IP\u5730\u5740]<\/ol>\n<\/li>\n<\/ol>\n<p>\uff08\u6ce8\u610f\uff09\u7531\u4e8eDB\u670d\u52a1\u5668\u672a\u8bbe\u7f6e\u6d6e\u52a8IP\uff0c\u65e0\u6cd5\u4ece\u5916\u90e8\u901a\u8fc7SSH\u767b\u5f55\u3002<br \/>\n\u5728Web\u670d\u52a1\u5668\u4e0a\u653e\u7f6e\u7528\u4e8e\u8fde\u63a5DB\u670d\u52a1\u5668\u7684\u79c1\u94a5\uff0c\u5e76\u901a\u8fc7SSH\u767b\u5f55DB\u670d\u52a1\u5668\u3002<br \/>\n\u203b\u5728Web\u670d\u52a1\u5668\u4e0a\u8fdb\u884c\u64cd\u4f5c<br \/>\n$ ssh -i [\u79c1\u94a5\u6587\u4ef6\u540d] root@[DB\u670d\u52a1\u5668\u7684IP\u5730\u5740]<\/p>\n<p>\u521b\u5efa\u7528\u6237<br \/>\n\u7531\u4e8eVPC\u865a\u62df\u5b9e\u4f8b\u7684\u521d\u59cb\u72b6\u6001\u4e0b\u6ca1\u6709\u4e00\u822c\u7528\u6237\uff0c\u56e0\u6b64\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5177\u6709sudo\u6743\u9650\u7684\u4e00\u822c\u7528\u6237\u4ee5\u8fdb\u884c\u64cd\u4f5c\u3002<br \/>\n$ adduser [\u7528\u6237\u540d]<br \/>\n$ gpasswd -a [\u7528\u6237\u540d] sudo<\/p>\n<p>\u521b\u5efa\u7528\u6237\u540e\uff0c\u5207\u6362\u5230\u521b\u5efa\u7684\u7528\u6237\u5e76\u8fdb\u884c\u64cd\u4f5c\u3002<br \/>\n$ su &#8211; [\u7528\u6237\u540d]<\/p>\n<p>\u66f4\u65b0\u8f6f\u4ef6\u5305\u5217\u8868<br \/>\n\u6267\u884c\u8f6f\u4ef6\u5305\u5217\u8868\u7684\u66f4\u65b0\u3002<br \/>\n$ sudo apt-get update<\/p>\n<h2>\u5b89\u88c5Python\u7684PostgreSQL\u5ba2\u6237\u7aef\u5e93<\/h2>\n<ul class=\"post-ul\">Web\u30b5\u30fc\u30d0\u30fc\u3067\u306e\u4f5c\u696d<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728\u4e2d\u6587\u4e2d\uff0c\u539f\u6587\u53ef\u4ee5\u88ab\u7b80\u6d01\u5730\u8868\u8fbe\u4e3a\u4ee5\u4e0b\u65b9\u5f0f\uff1a<\/ol>\n<\/li>\n<\/ol>\n<p>\u5b89\u88c5Python3\u3001pip\u548cPostgreSQL\u5ba2\u6237\u7aef<br \/>\n\u5b89\u88c5\u7528\u4e8e\u8fde\u63a5Python3\u3001pip\u548cPostgreSQL\u7684\u5ba2\u6237\u7aef<br \/>\n$ sudo apt-get install python3-pip python3-dev libpq-dev postgresql-client-12<\/p>\n<h2>\u5b89\u88c5PostgreSQL<\/h2>\n<ul class=\"post-ul\">DB\u30b5\u30fc\u30d0\u30fc\u3067\u306e\u4f5c\u696d<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5b89\u88c5PostgreSQL\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>$ sudo apt-get install postgresql postgresql-contrib<\/ol>\n<\/li>\n<\/ol>\n<p>\u786e\u8ba4PostgreSQL\u7248\u672c\u5e76\u68c0\u67e5\u662f\u5426\u6b63\u5728\u8fd0\u884c\u3002<br \/>\n\u5728Ubuntu 20.04\u4e2d\uff0c\u5b89\u88c5\u7684PostgreSQL\u7248\u672c\u662f12\u3002<br \/>\n$ psql &#8211;version<br \/>\npsql (PostgreSQL) 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1)<\/p>\n<p>$ sudo systemctl status postgresql<br \/>\n\u25cf postgresql.service &#8211; PostgreSQL RDBMS<br \/>\nLoaded: loaded (\/lib\/systemd\/system\/postgresql.service; enabled; vendor preset: enabled)<br \/>\nActive: active (exited) since Fri 2022-09-30 15:05:10 UTC; 2min 33s ago<br \/>\nMain PID: 3642 (code=exited, status=0\/SUCCESS)<br \/>\nTasks: 0 (limit: 9508)<br \/>\nMemory: 0B<br \/>\nCGroup: \/system.slice\/postgresql.service<\/p>\n<p>Sep 30 15:05:10 poll-db systemd[1]: Starting PostgreSQL RDBMS&#8230;<br \/>\nSep 30 15:05:10 poll-db systemd[1]: Finished PostgreSQL RDBMS.<\/p>\n<p>\u521b\u5efaPostgreSQL\u6570\u636e\u5e93\u548c\u8fde\u63a5\u7528\u6237\u3002<br \/>\n\u767b\u5f55\u5230PostgreSQL\u6570\u636e\u5e93\u3002<br \/>\n$ sudo su &#8211; postgres<br \/>\n$ psql<br \/>\npsql (12.12 (Ubuntu 12.12-0ubuntu0.20.04.1))<br \/>\nType &#8220;help&#8221; for help.<\/p>\n<p>\u521b\u5efa\u6570\u636e\u5e93<br \/>\npostgres=# CREATE DATABASE polls;<br \/>\nCREATE DATABASE<\/p>\n<p>\u521b\u5efa\u7528\u6237(Django\u8fde\u63a5\u6240\u9700\u7684\u7528\u6237\u548c\u5bc6\u7801)<br \/>\npostgres=# CREATE USER poll_user WITH PASSWORD &#8216;poll_password&#8217;;<br \/>\nCREATE ROLE<\/p>\n<p>\u6388\u6743\u7ed9\u521b\u5efa\u7684\u7528\u6237<br \/>\npostgres=# GRANT ALL PRIVILEGES ON DATABASE polls TO poll_user;<br \/>\nGRANT<\/p>\n<p>\u9000\u51fa\u6570\u636e\u5e93<br \/>\npostgres=# \\q<\/p>\n<p>\u4fee\u6539PostreSQL\u914d\u7f6e\u6587\u4ef6\uff08postgresql.conf\uff09\u3002<br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8bbe\u7f6e\u7684\u662f\u53ea\u76d1\u542clocalhost\uff0c\u4e3a\u4e86\u80fd\u591f\u4ece\u5916\u90e8\u8fde\u63a5\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\uff0c\u5c06listen_addresses\u66f4\u6539\u4e3a\u201c*\u201d\u3002<br \/>\n$ cd \/etc\/postgresql\/12\/main\/<br \/>\n$ vi postgresql.conf<\/p>\n<p>\u4fee\u6539\u524d\uff08\u7b2c60\u884c\uff09<\/p>\n<p>#listen_addresses = &#8216;localhost&#8217; # what IP address(es) to listen on;<\/p>\n<p>\u4fee\u6539\u540e\uff08\u7b2c60\u884c\uff09<\/p>\n<p>listen_addresses = &#8216;*&#8217; # what IP address(es) to listen on;<\/p>\n<p>\u4fee\u6539PostgreSQL\u914d\u7f6e\u6587\u4ef6\uff08pg_hba.conf\uff09\u3002<br \/>\n\u4e3a\u4e86\u8ba9Web\u670d\u52a1\u5668\u80fd\u591f\u8fde\u63a5\u5230PostgreSQL\uff0c\u9700\u8981\u5728pg_hba.conf\u4e2d\u6dfb\u52a0\u8ba9Web\u670d\u52a1\u5668\u5b50\u7f51\uff08\u4f8b\u5982\uff1a10.10.0.0\/24\uff09\u4ee5md5\u8eab\u4efd\u9a8c\u8bc1\u65b9\u5f0f\u8fde\u63a5\u7684\u914d\u7f6e\u3002<br \/>\n$ vi pg_hba.conf<\/p>\n<p>\u6dfb\u52a0\u5230\u672b\u5c3e\u7684\u5185\u5bb9<\/p>\n<p>host all all 10.10.0.0\/24 md5<\/p>\n<p>\u5207\u6362\u56de\u5de5\u4f5c\u7528\u6237\u4ecepostgresql\u7528\u6237\u3002<br \/>\n$ exit<br \/>\nlogout<\/p>\n<p>\u91cd\u65b0\u542f\u52a8PostgreSQL\u4ee5\u5e94\u7528\u66f4\u6539\uff08\u5728\u5de5\u4f5c\u7528\u6237\u4e0b\u6267\u884c\uff09\u3002<br \/>\n$ sudo systemctl restart postgresql<\/p>\n<p>\u68c0\u67e5PostgreSQL\u72b6\u6001\uff0c\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\u9519\u8bef\uff0c\u5219\u5e94\u8be5\u5904\u4e8e\u8fd0\u884c\u72b6\u6001\u3002<br \/>\n$ sudo systemctl status postgresql<br \/>\n\u25cf postgresql.service &#8211; PostgreSQL RDBMS<br \/>\nLoaded: loaded (\/lib\/systemd\/system\/postgresql.service; enabled; vendor preset: enabled)<br \/>\nActive: active (exited) since Sun 2022-10-02 02:44:42 UTC; 7s ago<br \/>\nProcess: 16723 ExecStart=\/bin\/true (code=exited, status=0\/SUCCESS)<br \/>\nMain PID: 16723 (code=exited, status=0\/SUCCESS)<\/p>\n<p>Oct 02 02:44:42 poll-db systemd[1]: Starting PostgreSQL RDBMS&#8230;<br \/>\nOct 02 02:44:42 poll-db systemd[1]: Finished PostgreSQL RDBMS.<\/p>\n<h2>\u786e\u8ba4\u8fde\u63a5\uff08\u4eceWeb\u670d\u52a1\u5668\u5230PostgreSQL\uff09<\/h2>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Web\u30b5\u30fc\u30d0\u30fc\u3067\u306e\u4f5c\u696d<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">PostgreSQL\u30b5\u30fc\u30d0\u306e\u8a2d\u5b9a\u304c\u7d42\u308f\u3063\u305f\u306e\u3067\u3001Web\u30b5\u30fc\u30d0\u304b\u3089PostgreSQL\u30b5\u30fc\u30d0\u3078\u306e\u63a5\u7d9a\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8bf7\u786e\u8ba4\u5df2\u5b89\u88c5PostgreSQL\u7684psql\u5ba2\u6237\u7aef\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\uff0c\u5219\u53ef\u4ee5\u786e\u8ba4\u5176\u7248\u672c\u4e3a12\u3002\u5982\u679c\u6ca1\u6709psql\u547d\u4ee4\uff0c\u8bf7\u4eceUbuntu\u7684\u521d\u59cb\u8bbe\u7f6e\u5f00\u59cb\u786e\u8ba4\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>$ psql &#8211;version<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>psql (PostgreSQL) 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1)<\/ol>\n<\/li>\n<\/ol>\n<p>\u4f7f\u7528psql\u547d\u4ee4\u8fde\u63a5\u5230PostgreSQL\u6570\u636e\u5e93\u3002<br \/>\n$ psql -h [PostgreSQL\u670d\u52a1\u5668\u7684IP\u5730\u5740] -U [PostgreSQL\u7528\u6237\u540d] [\u6570\u636e\u5e93\u540d]<br \/>\n\u7528\u6237poll_user\u7684\u5bc6\u7801\uff1a[\u8f93\u5165\u5bc6\u7801]<\/p>\n<p>\u5982\u679c\u6210\u529f\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u5c06\u663e\u793a\u4ee5\u4e0b\u63d0\u793a\u7b26\u3002<br \/>\npsql (12.12 (Ubuntu 12.12-0ubuntu0.20.04.1))<br \/>\nSSL\u8fde\u63a5\uff08\u534f\u8bae\uff1aTLSv1.3\uff0c\u52a0\u5bc6\u65b9\u5f0f\uff1aTLS_AES_256_GCM_SHA384\uff0c\u4f4d\u6570\uff1a256\uff0c\u538b\u7f29\uff1a\u5173\u95ed\uff09<br \/>\n\u8f93\u5165&#8221;help&#8221;\u83b7\u53d6\u5e2e\u52a9\u3002<\/p>\n<p>\u8981\u786e\u8ba4\u662f\u5426\u6210\u529f\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u8bf7\u6267\u884c&#8221;\u00a5l&#8221;\u547d\u4ee4\u4ee5\u663e\u793a\u6570\u636e\u5e93\u5217\u8868\u3002<br \/>\n\u8bf7\u786e\u8ba4\u5217\u8868\u4e2d\u663e\u793a\u4e86template0\u3001template1\u3001postgresql\uff0c\u4ee5\u53ca\u521b\u5efa\u7684\u6570\u636e\u5e93\uff08\u4f8b\u5982\uff1apolls\uff09\u3002<br \/>\npolls=&gt; \\l<br \/>\n\u6570\u636e\u5e93\u5217\u8868<br \/>\n\u540d\u79f0 | \u6240\u6709\u8005 | \u7f16\u7801 | \u6821\u5bf9\u987a\u5e8f | ctype | \u8bbf\u95ee\u6743\u9650<br \/>\n&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\npolls | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =Tc\/postgres +<br \/>\n| | | | | postgres=CTc\/postgres +<br \/>\n| | | | | poll_user=CTc\/postgres<br \/>\npostgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |<br \/>\ntemplate0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c\/postgres +<br \/>\n| | | | | postgres=CTc\/postgres<br \/>\ntemplate1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c\/postgres +<br \/>\n| | | | | postgres=CTc\/postgres<br \/>\n(4 \u884c)<\/p>\n<p>\u73b0\u5728\uff0c\u4eceWeb\u670d\u52a1\u5668\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u8fde\u63a5\u5df2\u7ecf\u5efa\u7acb\u5b8c\u6210\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u521b\u5efaDjango\u73af\u5883\u3002<\/p>\n<h2>\u521b\u5efaDjango\u5f00\u53d1\u73af\u5883<\/h2>\n<ul class=\"post-ul\">Web\u30b5\u30fc\u30d0\u3067\u306e\u4f5c\u696d<\/ul>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4f7f\u7528pip\u547d\u4ee4\uff0c\u5b89\u88c5Django\u548cPython\u8fde\u63a5\u5230PostgreSQL\u7684\u9002\u914d\u5668&#8221;psycopg2&#8243;\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>$ sudo pip3 install Django==4.0.7 psycopg2<\/ol>\n<\/li>\n<\/ol>\n<p>\u8fd9\u6b21\uff0c\u6211\u4eec\u5b89\u88c5\u4e86Django\u7684\u7248\u672c4.0.7\uff0c\u4f46\u53ef\u5b89\u88c5\u7684\u7248\u672c\u5217\u8868\u5982\u4e0b\u6240\u793a\uff1a\u8f93\u5165\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u7248\u672c\u53f7\uff0c\u4f8b\u5982\uff1a<br \/>\n$ sudo pip3 install Django==4.xxxx<br \/>\nERROR: Could not find a version that satisfies the requirement Django==4.xxxx (from versions: 1.1.3, 1.1.4, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 1.2.7, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5,<br \/>\n&lt;&lt;\u7701\u7565&gt;&gt;<br \/>\n3.2.14, 3.2.15, 4.0a1, 4.0b1, 4.0rc1, 4.0, 4.0.1, 4.0.2, 4.0.3, 4.0.4, 4.0.5, 4.0.6, 4.0.7, 4.1a1, 4.1b1, 4.1rc1, 4.1, 4.1.1)<br \/>\nERROR: No matching distribution found for Django==4.xxxx<\/p>\n<h2>\u51c6\u5907Django\u5e94\u7528\u7a0b\u5e8f<\/h2>\n<p>\u672c\u6b21\u6211\u4eec\u5c06\u4f7f\u7528Django\u7684\u201c\u7b80\u5355\u6295\u7968\u5e94\u7528\u7a0b\u5e8f\u201d\u6765\u8fdb\u884c\u64cd\u4f5c\u786e\u8ba4\uff0c\u8fd9\u662f\u7b2c\u4e00\u6b21\u521b\u5efaDjango\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u8fd9\u662f\u4e00\u6bb5\u53e4\u8001\u7684\u6e90\u4ee3\u7801\uff0c\u4f46\u5728 Github \u7684 DigitalOcean Community \u4e2d\u627e\u5230\u4e86\u4e00\u4e2a\u540d\u4e3a\u201c\u7b80\u5355\u6295\u7968\u5e94\u7528\u7a0b\u5e8f\u201d\u7684\u9879\u76ee\uff0c\u6240\u4ee5\u6211\u5c06\u4f7f\u7528\u8fd9\u4e2a\u6e90\u4ee3\u7801\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4eceGitHub\u7684\u4ed3\u5e93\u4e2d\u514b\u9686\u4e0b\u6765\u4e00\u4e2a\u7b80\u5355\u7684\u6295\u7968\u5e94\u7528\u7a0b\u5e8f\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>$ git clone https:\/\/github.com\/do-community\/Django-polls.git<\/ol>\n<\/li>\n<\/ol>\n<p>\u514b\u9686\u5b8c\u6210\u540e\uff0c\u5c06\u521b\u5efa\u4e00\u4e2a Django-polls \u6587\u4ef6\u5939\u3002\u6211\u4eec\u5e0c\u671b\u5728\/app\u6587\u4ef6\u5939\u4e2d\u8fd0\u884c\uff0c\u6240\u4ee5\u5c06 Django-polls \u66f4\u6539\u4e3a\/app\uff0c\u5e76\u5c06\u6587\u4ef6\u5939\u7684\u6743\u9650\u66f4\u6539\u4e3a\u5de5\u4f5c\u7528\u6237\uff08\u4f8b\u5982\uff1adai.dai\uff09\u3002<br \/>\n$ sudo mv Django-polls \/app<br \/>\n$ sudo chown -R dai.dai \/app<\/p>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\/app\u6587\u4ef6\u5939\u7684\u7ed3\u6784\u5982\u4e0b\u6240\u793a\uff0c\u7531Django\u9879\u76ee\u7684\u6587\u4ef6\u7ec4\u6210\u3002<br \/>\n$ ls -l \/app<br \/>\ntotal 24<br \/>\n-rw-rw-r&#8211; 1 dai dai 1079 Oct 2 02:50 LICENSE<br \/>\n-rw-rw-r&#8211; 1 dai dai 1359 Oct 2 02:50 README.md<br \/>\n-rwxrwxr-x 1 dai dai 538 Oct 2 02:50 manage.py<br \/>\ndrwxrwxr-x 2 dai dai 4096 Oct 2 02:50 mysite<br \/>\ndrwxrwxr-x 5 dai dai 4096 Oct 2 02:50 polls<br \/>\ndrwxrwxr-x 3 dai dai 4096 Oct 2 02:50 templates<\/p>\n<h3>Django\u7684\u8a2d\u5b9a\u6587\u4ef6settings.py\u7684\u8a2d\u5b9a\u3002<\/h3>\n<p>\u7f16\u8f91Django\u7684\u8bbe\u7f6e\u6587\u4ef6settings.py\u3002<\/p>\n<p>\u4fee\u6539\u90e8\u5206\u5305\u62ec\u4ee5\u4e0b3\u4e2a\u53c2\u6570\u3002<\/p>\n<pre class=\"post-pre\"><code>- SECRET_KEY \r\n- ALLOWED_HOSTS\r\n- DATABASE\r\n<\/code><\/pre>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u91cd\u65b0\u751f\u6210secret_key<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u7531\u4e8e\u53c2\u6570\u5982\u4e0b\u6240\u793a\uff0cSECRET_KEY\u5c06\u91cd\u65b0\u751f\u6210\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>SECRET_KEY = &#8216;your_secret_key_here&#8217;<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4f7f\u7528Django\u7ba1\u7406\u811a\u672cmanage.py\u542f\u52a8Shell\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>$ python3 manage.py shell<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>Python 3.8.10 (default, Jun 22 2022, 20:18:18)<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>[GCC 9.4.0] on linux<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u952e\u5165&#8221;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221;\u6216&#8221;license&#8221;\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>(InteractiveConsole)<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>&gt;&gt;&gt;<\/ol>\n<\/li>\n<\/ol>\n<p>\u542f\u52a8Shell\u540e\uff0c\u6267\u884c\u4ee5\u4e0b\u5185\u5bb9\u4ee5\u91cd\u65b0\u751f\u6210secret_key\u3002<br \/>\nfrom Django.core.management.utils import get_random_secret_key<br \/>\nsecret_key = get_random_secret_key()<br \/>\ntext = &#8216;SECRET_KEY = \\'{0}\\&#8221;.format(secret_key)<br \/>\nprint(text)<\/p>\n<p>\u5c06\u8f93\u51fa\u7ed3\u679c\u586b\u5165settings.py\u4e2d\u7684SECRET_KEY\u503c\u3002<\/p>\n<p>\u66f4\u6539\u524d<\/p>\n<p>SECRET_KEY = &#8216;your_secret_key_here&#8217;<\/p>\n<p>\u66f4\u6539\u540e<\/p>\n<p>SECRET_KEY = &#8216;xxxtx!u3j@ix8h59_xxxbjc8u1l_y+f&amp;d%_l!rc_cus@ua9xxx&#8217;<\/p>\n<p>ALLOWED_HOSTS\uff08\u8bbf\u95ee\u6743\u9650\u8bbe\u7f6e\uff09<br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53ea\u5141\u8bb8localhost\u8fde\u63a5\uff0c\u56e0\u6b64\u9700\u8981\u8bbe\u7f6e\u4e3a\u5141\u8bb8\u5168\u90e8 *\uff0c\u6216Web\u670d\u52a1\u5668\u7684IP\u5730\u5740\u3002<\/p>\n<p>\u66f4\u6539\u524d<\/p>\n<p>ALLOWED_HOSTS = []<\/p>\n<p>\u66f4\u6539\u540e<\/p>\n<p>\u203b\u5982\u679c\u8981\u5141\u8bb8\u5168\u90e8<br \/>\nALLOWED_HOSTS = [&#8216;*&#8217;]<br \/>\n\uff0a\u5982\u679c\u8981\u6307\u5b9aIP\u5730\u5740<br \/>\nALLOWED_HOSTS = [&#8216;111.222.333.444&#8217;]<\/p>\n<p>\u6570\u636e\u5e93\u8bbe\u7f6e<br \/>\n\u8fdb\u884c\u4e0eDjango\u8fde\u63a5\u6570\u636e\u5e93\u7684\u8bbe\u7f6e\u3002\u521d\u59cb\u8bbe\u7f6e\u4f7f\u7528sqlite3\uff0c\u73b0\u5728\u6539\u4e3a\u8bbe\u7f6e\u4e3aPostgreSQL\u3002<\/p>\n<p>\u66f4\u6539\u524d<\/p>\n<p>DATABASES = {<br \/>\n&#8216;default&#8217;: {<br \/>\n&#8216;ENGINE&#8217;: &#8216;Django.db.backends.sqlite3&#8217;,<br \/>\n&#8216;NAME&#8217;: os.path.join(BASE_DIR, &#8216;db.sqlite3&#8217;),<br \/>\n}<br \/>\n}<\/p>\n<p>\u66f4\u6539\u540e<\/p>\n<p>DATABASES = {<br \/>\n&#8216;default&#8217;: {<br \/>\n&#8216;ENGINE&#8217;: &#8216;Django.db.backends.postgresql_psycopg2&#8217;,<br \/>\n&#8216;NAME&#8217;: &#8216;\u6570\u636e\u5e93\u540d\u79f0&#8217;,<br \/>\n&#8216;USER&#8217;: &#8216;PostgreSQL\u8fde\u63a5\u7528\u6237\u540d&#8217;,<br \/>\n&#8216;PASSWORD&#8217;: &#8216;PostgreSQL\u8fde\u63a5\u7528\u6237\u7684\u5bc6\u7801&#8217;,<br \/>\n&#8216;HOST&#8217;: &#8216;\u6570\u636e\u5e93\u8fde\u63a5\u7684IP\u5730\u5740&#8217;,<br \/>\n&#8216;PORT&#8217;: &#8216;\u8fde\u63a5\u5230PostgresQL\u7684\u7aef\u53e3\u53f7&#8217;,<br \/>\n}<br \/>\n}<\/p>\n<h3>\u6267\u884c\u8fc1\u79fb<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u6267\u884cDjango\u7684\u8fc1\u79fb\u547d\u4ee4\uff0c\u751f\u6210\u6570\u636e\u5e93\u7684\u6a21\u5f0f\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>$ python3 manage.py migrate<\/ol>\n<\/li>\n<\/ol>\n<p>\u6267\u884c\u8be5\u547d\u4ee4\u540e\uff0c\u4f1a\u8f93\u51fa\u4ee5\u4e0b\u5185\u5bb9\uff0c\u5e76\u5728\u6700\u540e\u7ee7\u7eed\u663e\u793a&#8221;Applying&#8221;\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6ca1\u6709\u4efb\u4f55\u8f93\u51fa\uff0c\u5219\u53ef\u80fd\u662f\u65e0\u6cd5\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002\u8bf7\u68c0\u67e5settings.py\u6587\u4ef6\u7684\u8bbe\u7f6e\u3002<br \/>\n\u7cfb\u7edf\u68c0\u67e5\u53d1\u73b0\u4e86\u4e00\u4e9b\u95ee\u9898\uff1a<\/p>\n<p>\u8b66\u544a\uff1a<br \/>\npolls.Choice\uff1a\uff08models.W042\uff09\u5728\u6ca1\u6709\u5b9a\u4e49\u4e3b\u952e\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u81ea\u52a8\u751f\u6210\u7684\u4e3b\u952e\uff0c\u9ed8\u8ba4\u4e3a&#8217;Django.db.models.AutoField&#8217;\u3002<br \/>\n\u63d0\u793a\uff1a\u914d\u7f6eDEFAULT_AUTO_FIELD\u8bbe\u7f6e\u6216\u8005\u8bbe\u7f6ePollsConfig.default_auto_field\u5c5e\u6027\uff0c\u4ee5\u6307\u5411AutoField\u7684\u5b50\u7c7b\uff0c\u4f8b\u5982&#8217;Django.db.models.BigAutoField&#8217;\u3002<br \/>\npolls.Question\uff1a\uff08models.W042\uff09\u5728\u6ca1\u6709\u5b9a\u4e49\u4e3b\u952e\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u81ea\u52a8\u751f\u6210\u7684\u4e3b\u952e\uff0c\u9ed8\u8ba4\u4e3a&#8217;Django.db.models.AutoField&#8217;\u3002<br \/>\n\u63d0\u793a\uff1a\u914d\u7f6eDEFAULT_AUTO_FIELD\u8bbe\u7f6e\u6216\u8005\u8bbe\u7f6ePollsConfig.default_auto_field\u5c5e\u6027\uff0c\u4ee5\u6307\u5411AutoField\u7684\u5b50\u7c7b\uff0c\u4f8b\u5982&#8217;Django.db.models.BigAutoField&#8217;\u3002<br \/>\n\u8981\u6267\u884c\u7684\u64cd\u4f5c\uff1a<br \/>\n\u5e94\u7528\u6240\u6709\u8fc1\u79fb\uff1aadmin\uff0cauth\uff0ccontenttypes\uff0cpolls\uff0csessions<br \/>\n\u6b63\u5728\u6267\u884c\u8fc1\u79fb\uff1a<br \/>\n\u5e94\u7528contenttypes.0001_initial&#8230; OK<br \/>\n\u5e94\u7528auth.0001_initial&#8230; OK<br \/>\n\u5e94\u7528admin.0001_initial&#8230; OK<br \/>\n\u5e94\u7528admin.0002_logentry_remove_auto_add&#8230; OK<br \/>\n\u5e94\u7528admin.0003_logentry_add_action_flag_choices&#8230; OK<br \/>\n\u5e94\u7528contenttypes.0002_remove_content_type_name&#8230; OK<br \/>\n\u5e94\u7528auth.0002_alter_permission_name_max_length&#8230; OK<br \/>\n\u5e94\u7528auth.0003_alter_user_email_max_length&#8230; OK<br \/>\n\u5e94\u7528auth.0004_alter_user_username_opts&#8230; OK<br \/>\n\u5e94\u7528auth.0005_alter_user_last_login_null&#8230; OK<br \/>\n\u5e94\u7528auth.0006_require_contenttypes_0002&#8230; OK<br \/>\n\u5e94\u7528auth.0007_alter_validators_add_error_messages&#8230; OK<br \/>\n\u5e94\u7528auth.0008_alter_user_username_max_length&#8230; OK<br \/>\n\u5e94\u7528auth.0009_alter_user_last_name_max_length&#8230; OK<br \/>\n\u5e94\u7528auth.0010_alter_group_name_max_length&#8230; OK<br \/>\n\u5e94\u7528auth.0011_update_proxy_permissions&#8230; OK<br \/>\n\u5e94\u7528auth.0012_alter_user_first_name_max_length&#8230; OK<br \/>\n\u5e94\u7528polls.0001_initial&#8230; OK<br \/>\n\u5e94\u7528sessions.0001_initial&#8230; OK<\/p>\n<h3>\u521b\u5efaDjango\u7684\u8d85\u7ea7\u7528\u6237<\/h3>\n<p>\u6ce8\u518cDjango\u7684\u8d85\u7ea7\u7528\u6237\u3002\u5728\u7b80\u5355\u6295\u7968\uff08poll\uff09\u5e94\u7528\u7a0b\u5e8f\u7684\u7ba1\u7406\u754c\u9762\u4e2d\uff0c\u4f7f\u7528\u6b64\u5904\u521b\u5efa\u7684\u7528\u6237\u767b\u5f55\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"gp\">$<\/span> python3 manage.py createsuperuser\r\n<span class=\"go\">\r\nUsername (leave blank to use 'dai'): [\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u5165\u529b]\r\nEmail address: [\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u5165\u529b]\r\nPassword:  [\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b]\r\nPassword (again): [\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b] \r\nSuperuser created successfully.\r\n<\/span><\/code><\/pre>\n<h3>\u521b\u5efa\u6f14\u793a\u6570\u636e<\/h3>\n<p>\u6211\u5011\u5c07\u88fd\u4f5c\u4e00\u500b\u5373\u5c07\u555f\u52d5\u7684\u300c\u7c21\u55ae\u6295\u7968\u61c9\u7528\u7a0b\u5f0f\u300d\u7684\u793a\u7bc4\u8cc7\u6599\u3002<br \/>\n\u9019\u6b21\u6211\u5011\u5c07\u5275\u5efa\u4e00\u500b\u6709\u95dc\u4eca\u5929\u5929\u6c23\u7684\u6295\u7968\u6578\u64da\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u4eca\u65e5\u306e\u5929\u6c17<\/ul>\n<\/li>\n<\/ul>\n<p>\u8cea\u554f: \u4eca\u65e5\u306e\u5929\u6c17\u306f\uff1f<br \/>\n\u56de\u7b54: 1.\u96e8\u30012.\u66c7\u308a\u30013.\u6674\u308c<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4f7f\u7528Django\u7684\u7ba1\u7406\u811a\u672cmanage.py\u542f\u52a8Shell\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>$ python3 manage.py shell<\/ol>\n<\/li>\n<\/ol>\n<p>\u5728Shell\u4e2d\u6267\u884c\u4ee5\u4e0b\u5185\u5bb9\uff0c\u5c06\u6570\u636e\u5b58\u5165\u6570\u636e\u5e93\u3002<br \/>\nfrom polls.models import Choice, Question<br \/>\nfrom Django.utils import timezone<br \/>\nq = Question(question_text=&#8221;\u4eca\u5929\u7684\u5929\u6c14&#8221;, pub_date=timezone.now())<br \/>\nq.save()<br \/>\nq.question_text = &#8220;\u4eca\u5929\u7684\u5929\u6c14\u662f\uff1f&#8221;<br \/>\nq.save()<br \/>\nq.choice_set.create(choice_text=&#8217;\u96e8&#8217;, votes=0)<br \/>\nq.choice_set.create(choice_text=&#8217;\u591a\u4e91&#8217;, votes=0)<br \/>\nq.choice_set.create(choice_text=&#8217;\u6674\u6717&#8217;, votes=0)<br \/>\nexit<\/p>\n<p>\u73b0\u5728\uff0c\u51c6\u5907\u5de5\u4f5c\u5df2\u7ecf\u5b8c\u6210\u3002\u63a5\u4e0b\u6765\u53ea\u9700\u8981\u542f\u52a8Web\u670d\u52a1\u5668\uff01<\/p>\n<h2>\u786e\u8ba4\u52a8\u4f5c\uff1a\u542f\u52a8Web\u670d\u52a1\u5668<\/h2>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4f7f\u7528Django\u7684runserver[\u6d4b\u8bd5\u7528\u7b80\u6613\u670d\u52a1\u5668]\u6765\u542f\u52a8\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>0.0.0.0:8000\u662f\u6307\u53ef\u4ee5\u63a5\u53d7\u6765\u81ea\u4efb\u4f55IP\u5730\u5740\u76848000\u7aef\u53e3\u7684\u610f\u601d\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>$ python3 manage.py runserver 0.0.0.0:8000<\/ol>\n<\/li>\n<\/ol>\n<p>\u5982\u679c\u6210\u529f\u542f\u52a8\uff0c\u5c06\u4f1a\u8f93\u51fa\u4ee5\u4e0b\u4fe1\u606f\uff1aStarting development server&#8230;<br \/>\n\u7cfb\u7edf\u68c0\u67e5\u53d1\u73b02\u4e2a\u95ee\u9898\uff080\u4e2a\u88ab\u5c4f\u853d\uff09\u3002<br \/>\n2022\u5e7410\u670802\u65e5 &#8211; 03:05:12<br \/>\n\u4f7f\u7528\u8bbe\u7f6e&#8217;mysite.settings&#8217;\u7684Django\u7248\u672c\u4e3a4.0.7<br \/>\n\u5728http:\/\/0.0.0.0:8000\/\u4e0a\u542f\u52a8\u5f00\u53d1\u670d\u52a1\u5668<br \/>\n\u4f7f\u7528CONTROL-C\u9000\u51fa\u670d\u52a1\u5668\u3002<\/p>\n<p>\u5728\u6d4f\u89c8\u5668\u4e2d\uff0c\u4f7f\u7528Web\u670d\u52a1\u5668\u7684\u6d6e\u52a8IP\u5730\u5740\uff0c\u8bbf\u95ee\u4ee5\u4e0bURL\uff1a&#8221;http:\/\/(\u6d6e\u52a8IP\u5730\u5740):8000\/polls&#8221;\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d49ee37434c4406cb1598\/49-0.png\" alt=\"\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u753b\u9762\u9077\u79fb\u56f3\" \/><\/div>\n<p>\u5728\u6d4f\u89c8\u5668\u8bbf\u95ee\u65f6\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u63a7\u5236\u53f0\u786e\u8ba4\u4ee5\u4e0b\u7684\u8bbf\u95ee\u65e5\u5fd7\u6b63\u5728\u6d41\u52a8\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"go\">[03\/Oct\/2022 15:38:07] \"GET \/polls\/ HTTP\/1.1\" 200 549\r\n[03\/Oct\/2022 15:38:07] \"GET \/static\/polls\/style.css HTTP\/1.1\" 404 179\r\n[03\/Oct\/2022 15:38:07] \"GET \/polls\/1\/ HTTP\/1.1\" 200 945\r\n[03\/Oct\/2022 15:38:07] \"POST \/polls\/1\/vote\/ HTTP\/1.1\" 302 0\r\n[03\/Oct\/2022 15:38:07] \"GET \/polls\/1\/results\/ HTTP\/1.1\" 200 568\r\n[03\/Oct\/2022 15:38:07] \"GET \/polls\/1\/ HTTP\/1.1\" 200 945\r\n[03\/Oct\/2022 15:38:08] \"POST \/polls\/1\/vote\/ HTTP\/1.1\" 302 0\r\n[03\/Oct\/2022 15:38:08] \"GET \/polls\/1\/results\/ HTTP\/1.1\" 200 568\r\n[03\/Oct\/2022 15:38:08] \"GET \/polls\/1\/ HTTP\/1.1\" 200 945\r\n[03\/Oct\/2022 15:38:08] \"POST \/polls\/1\/vote\/ HTTP\/1.1\" 302 0\r\n[03\/Oct\/2022 15:38:08] \"GET \/polls\/1\/results\/ HTTP\/1.1\" 200 568\r\n[03\/Oct\/2022 15:38:08] \"GET \/polls\/1\/ HTTP\/1.1\" 200 945\r\n[03\/Oct\/2022 15:38:09] \"GET \/polls\/ HTTP\/1.1\" 200 549\r\n<\/span><\/code><\/pre>\n<h1>\u6700\u540e<\/h1>\n<p>\u73b0\u5728\uff0c\u6211\u5df2\u7ecf\u6210\u529f\u5730\u5c06Django\u5e94\u7528\u7a0b\u5e8f\u90e8\u7f72\u5728IBM Cloud\u7684Virtual Private Cloud\uff08VPC\uff09\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u3002<\/p>\n<p>\u4f5c\u4e3a\u4e0b\u4e00\u6b65\uff0c\u6211\u521b\u5efa\u4e86\u4e00\u7bc7\u5173\u4e8e\u5728\u57fa\u7840\u8bbe\u65bd\u548c\u5e94\u7528\u5c42\u9762\u4e0a\u8fdb\u884c\u53ef\u89c6\u5316\u548c\u76d1\u63a7\u7684\u6311\u6218\u7684Qiita\u6587\u7ae0\u3002\u8bf7\u540c\u65f6\u9605\u8bfb\u4ee5\u4e0b\u7684Qiita\u6587\u7ae0\u3002<\/p>\n<ul class=\"post-ul\">\u30a4\u30f3\u30d5\u30e9\u8996\u70b9\u3067\u306e\u53ef\u8996\u5316\u30fb\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u30a2\u30d7\u30ea\u8996\u70b9\u3067\u306e\u53ef\u8996\u5316\u30fb\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0<\/ul>\n<p>&nbsp;<\/p>\n<p>\u6211\u4f7f\u7528Django\u7684runserver\u4f5c\u4e3a\u8fd0\u884cDjango\u5e94\u7528\u7a0b\u5e8f\u7684Web\u670d\u52a1\u5668\uff0c\u4f46\u662f\u6211\u60f3\u5728\u53e6\u4e00\u7bc7\u6587\u7ae0\u4e2d\u5199\u5230uWSGI\u6216Gunicorn\u7684\u64cd\u4f5c\u65b9\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148 \u4ee5\u4e0b\u662f\u5728IBM Cloud\u7684Virtual Private Cloud\uff08VPC\uff09\u7684\u865a\u62df\u5b9e\u4f8b\u4e2d\u542f\u52a8Pyth [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-42017","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ibm-cloud-vpc\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efapython\uff08django\uff09\u5e94\u7528\u7a0b\u5e8f\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f\" \/>\n<meta property=\"og:description\" content=\"\u9996\u5148 \u4ee5\u4e0b\u662f\u5728IBM Cloud\u7684Virtual Private Cloud\uff08VPC\uff09\u7684\u865a\u62df\u5b9e\u4f8b\u4e2d\u542f\u52a8Pyth [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ibm-cloud-vpc\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efapython\uff08django\uff09\u5e94\u7528\u7a0b\u5e8f\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-11T20:59:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T02:32:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d49ee37434c4406cb1598\/4-0.png\" \/>\n<meta name=\"author\" content=\"\u9038, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u9038, \u79d1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/\",\"name\":\"\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2022-12-11T20:59:47+00:00\",\"dateModified\":\"2024-04-30T02:32:23+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/85c1dae56e6ea1e695c73d33c684d487\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/85c1dae56e6ea1e695c73d33c684d487\",\"name\":\"\u9038, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c94f6d9cbbfbca863fab309840bd690c153c95f8490c290ad2ed54dd693dad16?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c94f6d9cbbfbca863fab309840bd690c153c95f8490c290ad2ed54dd693dad16?s=96&d=mm&r=g\",\"caption\":\"\u9038, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keyi\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ibm-cloud-vpc\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efapython\uff08django\uff09\u5e94\u7528\u7a0b\u5e8f\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f","og_description":"\u9996\u5148 \u4ee5\u4e0b\u662f\u5728IBM Cloud\u7684Virtual Private Cloud\uff08VPC\uff09\u7684\u865a\u62df\u5b9e\u4f8b\u4e2d\u542f\u52a8Pyth [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ibm-cloud-vpc\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efapython\uff08django\uff09\u5e94\u7528\u7a0b\u5e8f\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2022-12-11T20:59:47+00:00","article_modified_time":"2024-04-30T02:32:23+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d49ee37434c4406cb1598\/4-0.png"}],"author":"\u9038, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u9038, \u79d1","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/","name":"\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2022-12-11T20:59:47+00:00","dateModified":"2024-04-30T02:32:23+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/85c1dae56e6ea1e695c73d33c684d487"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5728IBM Cloud VPC\u7684\u865a\u62df\u5b9e\u4f8b\u4e0a\u521b\u5efaPython\uff08Django\uff09\u5e94\u7528\u7a0b\u5e8f"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/85c1dae56e6ea1e695c73d33c684d487","name":"\u9038, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c94f6d9cbbfbca863fab309840bd690c153c95f8490c290ad2ed54dd693dad16?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c94f6d9cbbfbca863fab309840bd690c153c95f8490c290ad2ed54dd693dad16?s=96&d=mm&r=g","caption":"\u9038, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keyi\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ibm-cloud-vpc%e7%9a%84%e8%99%9a%e6%8b%9f%e5%ae%9e%e4%be%8b%e4%b8%8a%e5%88%9b%e5%bb%bapython%ef%bc%88django%ef%bc%89%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=42017"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42017\/revisions"}],"predecessor-version":[{"id":91377,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42017\/revisions\/91377"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=42017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=42017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=42017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}