{"id":1135,"date":"2018-07-11T14:30:22","date_gmt":"2018-07-11T06:30:22","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=1135"},"modified":"2018-07-18T13:33:00","modified_gmt":"2018-07-18T05:33:00","slug":"django%e5%ae%89%e8%a3%85%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=1135","title":{"rendered":"Django\u5b89\u88c5\u8fc7\u7a0b"},"content":{"rendered":"<p>\uff081\uff09\u5b89\u88c5python3<\/p>\n<p>\uff082\uff09\u5b89\u88c5\u6570\u636e\u5e93\u9a71\u52a8\uff1apip3 install mysqlclient<a href=\"https:\/\/www.5x44.cn\/?p=1133\">\u2460<\/a><\/p>\n<p>\uff083\uff09\u6d4b\u8bd5\u6570\u636e\u5e93\u8fde\u63a5\u60c5\u51b5\uff0c\u5199\u4e00\u4e2a.py\u7684\u6587\u4ef6\uff1a<br \/>\n<code><br \/>\n#!\/usr\/bin\/env python3<br \/>\nimport MySQLdb as mydb<br \/>\ndb = mydb.connect(user='t_user', host='localhost',db='mktest', passwd='test_user^', unix_socket='\/mnt\/mysqld\/mysql.sock')<br \/>\ncur = db.cursor()<br \/>\ncur.execute('select * from t1')<br \/>\nprint(cur.fetchall())<br \/>\ndb.close()<br \/>\n<\/code><br \/>\n\uff084\uff09\u5b89\u88c5virtualenv\u548cvirtualenvwrapper <a href=\"https:\/\/virtualenv.pypa.io\/en\/stable\/\">\u2461<\/a><a href=\"https:\/\/virtualenvwrapper.readthedocs.io\/en\/latest\/\">\u2462<\/a><br \/>\n<code>pip3 install virtualenv<\/code><\/p>\n<p>python3.6\u4e0d\u9700\u8981\u5b89\u88c5\u8fd9\u4e2a\u8f6f\u4ef6\u4e86\uff0c\u53ef\u4ee5\u4f7f\u7528python3 -m venv DIR\u7684\u65b9\u5f0f\u5efa\u7acb\u4e00\u4e2a\u865a\u62df\u8fd0\u884c\u73af\u5883.<\/p>\n<p>\uff085\uff09virtualenv ENV\uff08ENV\u662f\u76ee\u5f55\uff0cvirtualenv\u5728ENV\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u5efa\u7acb\u4e00\u4e2a\u865a\u62df\u8fd0\u884c\u73af\u5883\uff09<\/p>\n<p>\uff086\uff09\u8fdb\u5165ENV\uff0csource bin\/activate<\/p>\n<p>\uff087\uff09pip3 install django<br \/>\n\u5982\u679c\u9047\u5230\u4e0b\u9762\u8fd9\u79cd\u9519\u8bef\uff0c\u4e0d\u7528\u62c5\u5fc3\uff0c\u91cd\u65b0\u6267\u884c\u4e00\u6b21pip3 install django\u4e5f\u8bb8\u5c31\u597d\u4e86\uff0c\u6211\u5c31\u662f\u53cd\u590d\u5b89\u88c5\u4e86\u597d\u591a\u6b21\u624d\u5b89\u4e0a\u7684\u3002\u6211\u611f\u89c9\u662f\u7f51\u7edc\u4e2d\u65ad\u4e86\uff0c\u6240\u4ee5\u624d\u4e0b\u8f7d\u4e0d\u4e0b\u6765\u7684\u3002<\/p>\n<pre>Collecting django\r\n  Downloading https:\/\/files.pythonhosted.org\/packages\/ab\/15\/cfde97943f0db45e4f999c60b696fbb4df59e82bbccc686770f4e44c9094\/Django-2.0.7-py3-none-any.whl (7.1MB)\r\n    35% |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258d                    | 2.5MB 8.9kB\/s eta 0:08:38Exception:\r\nTraceback (most recent call last):\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_vendor\/urllib3\/response.py\", line 302, in _error_catcher\r\n    yield\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_vendor\/urllib3\/response.py\", line 384, in read\r\n    data = self._fp.read(amt)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_vendor\/cachecontrol\/filewrapper.py\", line 60, in read\r\n    data = self.__fp.read(amt)\r\n  File \"\/usr\/local\/lib\/python3.6\/http\/client.py\", line 449, in read\r\n    n = self.readinto(b)\r\n  File \"\/usr\/local\/lib\/python3.6\/http\/client.py\", line 493, in readinto\r\n    n = self.fp.readinto(b)\r\n  File \"\/usr\/local\/lib\/python3.6\/socket.py\", line 586, in readinto\r\n    return self._sock.recv_into(b)\r\n  File \"\/usr\/local\/lib\/python3.6\/ssl.py\", line 1009, in recv_into\r\n    return self.read(nbytes, buffer)\r\n  File \"\/usr\/local\/lib\/python3.6\/ssl.py\", line 871, in read\r\n    return self._sslobj.read(len, buffer)\r\n  File \"\/usr\/local\/lib\/python3.6\/ssl.py\", line 631, in read\r\n    v = self._sslobj.read(len, buffer)\r\nsocket.timeout: The read operation timed out\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/basecommand.py\", line 228, in main\r\n    status = self.run(options, args)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/commands\/install.py\", line 291, in run\r\n    resolver.resolve(requirement_set)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/resolve.py\", line 103, in resolve\r\n    self._resolve_one(requirement_set, req)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/resolve.py\", line 257, in _resolve_one\r\n    abstract_dist = self._get_abstract_dist_for(req_to_install)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/resolve.py\", line 210, in _get_abstract_dist_for\r\n    self.require_hashes\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/operations\/prepare.py\", line 310, in prepare_linked_requirement\r\n    progress_bar=self.progress_bar\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/download.py\", line 837, in unpack_url\r\n    progress_bar=progress_bar\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/download.py\", line 674, in unpack_http_url\r\n    progress_bar)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/download.py\", line 898, in _download_http_url\r\n    _download_url(resp, link, content_file, hashes, progress_bar)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/download.py\", line 618, in _download_url\r\n    hashes.check_against_chunks(downloaded_chunks)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/utils\/hashes.py\", line 48, in check_against_chunks\r\n    for chunk in chunks:\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/download.py\", line 586, in written_chunks\r\n    for chunk in chunks:\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/utils\/ui.py\", line 159, in iter\r\n    for x in it:\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_internal\/download.py\", line 575, in resp_read\r\n    decode_content=False):\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_vendor\/urllib3\/response.py\", line 436, in stream\r\n    data = self.read(amt=amt, decode_content=decode_content)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_vendor\/urllib3\/response.py\", line 401, in read\r\n    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)\r\n  File \"\/usr\/local\/lib\/python3.6\/contextlib.py\", line 99, in __exit__\r\n    self.gen.throw(type, value, traceback)\r\n  File \"\/home\/hank\/PY_TEST\/project1\/lib\/python3.6\/site-packages\/pip\/_vendor\/urllib3\/response.py\", line 307, in _error_catcher\r\n    raise ReadTimeoutError(self._pool, None, 'Read timed out.')\r\npip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uff081\uff09\u5b89\u88c5python3 \uff082\uff09\u5b89\u88c5\u6570\u636e\u5e93\u9a71\u52a8\uff1apip3 install mysqlclient\u2460 \uff083\uff09\u6d4b\u8bd5\u6570\u636e\u5e93\u8fde\u63a5\u60c5\u51b5\uff0c\u5199\u4e00\u4e2a.py\u7684\u6587\u4ef6\uff1a #!\/usr&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=1135\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-1135","post","type-post","status-publish","format-standard","hentry","category-django"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1135"}],"version-history":[{"count":7,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1135\/revisions"}],"predecessor-version":[{"id":1151,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1135\/revisions\/1151"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}