{"id":91,"date":"2023-07-11T12:08:59","date_gmt":"2023-07-11T04:08:59","guid":{"rendered":"http:\/\/www.leyiwangyou.top\/?p=91"},"modified":"2023-07-11T12:08:59","modified_gmt":"2023-07-11T04:08:59","slug":"django-%e5%85%a5%e9%97%a8%e4%b9%8b%e5%ae%89%e8%a3%85","status":"publish","type":"post","link":"http:\/\/www.leyiwangyou.top\/?p=91","title":{"rendered":"Django \u5165\u95e8\u4e4b\u5b89\u88c5"},"content":{"rendered":"<h1>Django makes it easier to build better web apps more quickly and with less code.<\/h1>\n<h4>1. What Python version can I use with Django?<\/h4>\n<table>\n<thead>\n<tr>\n<th>Django version<\/th>\n<th>Python versions<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>3.2<\/td>\n<td>3.6, 3.7, 3.8, 3.9, 3.10 (added in 3.2.9)<\/td>\n<\/tr>\n<tr>\n<td>4.0<\/td>\n<td>3.8, 3.9, 3.10<\/td>\n<\/tr>\n<tr>\n<td>4.1<\/td>\n<td>3.8, 3.9, 3.10, 3.11 (added in 4.1.3)<\/td>\n<\/tr>\n<tr>\n<td>4.2<\/td>\n<td>3.8, 3.9, 3.10, 3.11<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.  Get the latest official version<\/h4>\n<p><img decoding=\"async\" src=\"http:\/\/www.leyiwangyou.top\/wp-content\/uploads\/2023\/07\/img-20230711111215-300x140.png\" alt=\"\" \/><\/p>\n<pre><code>pip install Django==4.2.3<\/code><\/pre>\n<h4>3. Creating a project<\/h4>\n<pre><code>django-admin startproject mysite<\/code><\/pre>\n<pre><code>mysite\/\n    manage.py\n    mysite\/\n        __init__.py\n        settings.py\n        urls.py\n        asgi.py\n        wsgi.py<\/code><\/pre>\n<p>These files are:<\/p>\n<ul>\n<li>The outer <strong>mysite\/<\/strong> root directory is a container for your project. Its name doesn\u2019t matter to Django; you can rename it to anything you like.<\/li>\n<li><strong>manage.py<\/strong>: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin and manage.py.<\/li>\n<li>The inner mysite\/ directory is the actual Python package for your project. Its name is the Python package name you\u2019ll need to use to import anything inside it (e.g. mysite.urls).<\/li>\n<li>mysite\/<strong>init<\/strong>.py: An empty file that tells Python that this directory should be considered a Python package. If you\u2019re a Python beginner, read more about packages in the official Python docs.<\/li>\n<li>mysite\/settings.py: Settings\/configuration for this Django project. Django settings will tell you all about how settings work.<\/li>\n<li>mysite\/urls.py: The URL declarations for this Django project; a \u201ctable of contents\u201d of your Django-powered site. You can read more about URLs in URL dispatcher.<\/li>\n<li>mysite\/asgi.py: An entry-point for ASGI-compatible web servers to serve your project. See How to deploy with ASGI for more details.<\/li>\n<li>mysite\/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details.<\/li>\n<\/ul>\n<h4>4. The development server<\/h4>\n<pre><code>$ python manage.py runserver<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/www.leyiwangyou.top\/wp-content\/uploads\/2023\/07\/img-20230711115155-300x196.png\" alt=\"\" \/><\/p>\n<h4>\u95ee\u9898<\/h4>\n<hr \/>\n<ol>\n<li>\u5b89\u88c5\u5931\u8d25\n<pre><code>pip install Django==4.2.3\nCollecting Django==4.2.3\nDownloading Django-4.2.3-py3-none-any.whl (8.0 MB)\n ----------------------------- ---------- 5.9\/8.0 MB 3.5 kB\/s eta 0:09:42\nERROR: Exception:\nTraceback (most recent call last):\nFile &quot;E:\\software\\Python\\Python310\\lib\\site-packages\\pip\\_vendor\\urllib3\\response.py&quot;, line 438, in _error_catcher\nyield\nFile &quot;E:\\software\\Python\\Python310\\lib\\site-packages\\pip\\_vendor\\urllib3\\response.py&quot;, line 561, in read\ndata = self._fp_read(amt) if not fp_closed else b&quot;&quot;\nFile &quot;E:\\software\\Python\\Python310\\lib\\site-packages\\pip\\_vendor\\urllib3\\response.py&quot;, line 527, in _fp_read\nreturn self._fp.read(amt) if amt is not None else self._fp.read()\nFile &quot;E:\\software\\Python\\Python310\\lib\\site-packages\\pip\\_vendor\\cachecontrol\\filewrapper.py&quot;, line 90, in read\ndata = self.__fp.read(amt)\nFile &quot;E:\\software\\Python\\Python310\\lib\\http\\client.py&quot;, line 465, in read\ns = self.fp.read(amt)\nFile &quot;E:\\software\\Python\\Python310\\lib\\socket.py&quot;, line 705, in readinto\nreturn self._sock.recv_into(b)\nFile &quot;E:\\software\\Python\\Python310\\lib\\ssl.py&quot;, line 1274, in recv_into\nreturn self.read(nbytes, buffer)\nFile &quot;E:\\software\\Python\\Python310\\lib\\ssl.py&quot;, line 1130, in read\nreturn self._sslobj.read(len, buffer)\nTimeoutError: The read operation timed out<\/code><\/pre>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<br \/>\n\u589e\u52a0\u56fd\u5185\u955c\u50cf\u6e90\u5373\u53ef\u5b89\u88c5\u6210\u529f<\/p>\n<pre><code>pip install Django==4.2.3 -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\nLooking in indexes: https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\nCollecting Django==4.2.3\nDownloading https:\/\/pypi.tuna.tsinghua.edu.cn\/packages\/d4\/83\/227ebf197e413f3599cea96dddc7d6b8ff220310cc5b40dd0f1a15e5a9d1\/Django-4.2.3-py3-none-any.whl (8.0 MB)\n ---------------------------------------- 8.0\/8.0 MB 22.2 MB\/s eta 0:00:00\nCollecting asgiref&lt;4,&gt;=3.6.0 (from Django==4.2.3)\nDownloading https:\/\/pypi.tuna.tsinghua.edu.cn\/packages\/9b\/80\/b9051a4a07ad231558fcd8ffc89232711b4e618c15cb7a392a17384bbeef\/asgiref-3.7.2-py3-none-any.whl (24 kB)\nCollecting sqlparse&gt;=0.3.1 (from Django==4.2.3)\nDownloading https:\/\/pypi.tuna.tsinghua.edu.cn\/packages\/98\/5a\/66d7c9305baa9f11857f247d4ba761402cea75db6058ff850ed7128957b7\/sqlparse-0.4.4-py3-none-any.whl (41 kB)\n ---------------------------------------- 41.2\/41.2 kB ? eta 0:00:00\nRequirement already satisfied: tzdata in e:\\software\\python\\python310\\lib\\site-packages (from Django==4.2.3) (2023.3)\nCollecting typing-extensions&gt;=4 (from asgiref&lt;4,&gt;=3.6.0-&gt;Django==4.2.3)\nDownloading https:\/\/pypi.tuna.tsinghua.edu.cn\/packages\/ec\/6b\/63cc3df74987c36fe26157ee12e09e8f9db4de771e0f3404263117e75b95\/typing_extensions-4.7.1-py3-none-any.whl (33 kB)\nInstalling collected packages: typing-extensions, sqlparse, asgiref, Django\nSuccessfully installed Django-4.2.3 asgiref-3.7.2 sqlparse-0.4.4 typing-extensions-4.7.1<\/code><\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Django makes it easi<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-91","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=\/wp\/v2\/posts\/91","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=91"}],"version-history":[{"count":4,"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions"}],"predecessor-version":[{"id":97,"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions\/97"}],"wp:attachment":[{"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.leyiwangyou.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}