{"id":7382,"date":"2023-04-12T23:21:01","date_gmt":"2023-04-12T15:21:01","guid":{"rendered":"https:\/\/www.5x44.cn\/?p=7382"},"modified":"2023-04-17T13:53:19","modified_gmt":"2023-04-17T05:53:19","slug":"django%e7%9b%ae%e5%bd%95%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=7382","title":{"rendered":"\u7b2c\u4e00\u4e2adjango \u5e94\u7528[par1]"},"content":{"rendered":"\n<p>\u5728\u5b89\u88c5\u597ddjango\u6846\u67b6\u540e\uff0c\u4f7f\u7528<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-light-green-cyan-color\">django-admin startproject<\/mark><\/em>\u6765\u5efa\u7acb\u9879\u76ee\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">django-admin startproject mysite<\/mark><\/code><\/pre>\n\n\n\n<p>\u8fd9\u4f1a\u5728\u8fd0\u884c\u547d\u4ee4\u7684\u5f53\u524d\u76ee\u5f55\u5efa\u7acb\u4e00\u4e2a<strong>mysite<\/strong>\u7684\u6587\u4ef6\u5939\u3002\u5728\u5efa\u91cc\u9879\u76ee\u65f6\u8981\u907f\u514d\u4f7f\u7528python\u5185\u5efa\u540d\u6216Django\u7ec4\u4ef6\u540d\u5b57\uff0c\u5982\uff1adjango\u6216test\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u6765\u770b\u4e00\u4e0bstartproject\u90fd\u521b\u5efa\u4e86\u4ec0\u4e48\uff0c\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><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\n\n\n<ul class=\"wp-block-list\">\n<li>\u6700\u5916\u5c42\u7684<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">mysite\/<\/mark>\u662f\u6839\u76ee\u5f55\uff0c\u662f\u6574\u4e2a\u9879\u76ee\u7684\u5bb9\u5668\uff0c\u8fd9\u4e2a\u540d\u5b57\u4e0e\u9879\u76ee\u65e0\u5173\u7d27\u8981\uff0c\u53ef\u4ee5\u6539\u6210\u5176\u5b83\u7684\u540d\u5b57\u3002<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">manage.py<\/mark>\uff1a\u662f\u4e00\u4e2a\u4e0eDjango\u4ea4\u4e92\u7684\u547d\u4ee4\u884c\u5de5\u5177\u3002<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5185\u90e8\u7684<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">mysite\/<\/mark>\u6587\u4ef6\u5939\u662f\u4f60\u9879\u76ee\u5b9e\u9645\u7684python\u5305\u3002\u5b83\u7684\u540d\u5b57\u662fpython\u5305\u540d\uff0c\u9700\u8981\u7528\u5b83\u6765import\u5b83\u5185\u90e8\u7684\u4e1c\u897f\u3002\u5982:mysite.urls<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">mysite\/__init__.py<\/mark>\uff1a\u4e00\u4e2a\u7a7a\u6587\u4ef6\uff0c\u5b83\u544a\u8bc9python\u201c\u8fd9\u4e2a\u6587\u4ef6\u5939\u5e94\u8be5\u88ab\u770b\u505a\u662f\u4e00\u4e2apython\u5305\u201d\u3002<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">mysite\/settings.py<\/mark>\uff1a\u5bf9\u8fd9\u4e2aDjango\u9879\u76ee\u8fdb\u884c\u8bbe\u7f6e\u6216\u914d\u7f6e\u3002<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">mysite\/urls.py<\/mark>\uff1a\u5bf9\u8fd9\u4e2adjango\u9879\u76eeurl\u7684\u58f0\u660e\uff1b\u8be5\u7ad9\u70b9\u7684\u201c\u76ee\u5f55\u201d<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">mysite\/asgi.py\uff1a<\/mark>\u517c\u5bb9ASGI\u7684web\u670d\u52a1\u5668\u5165\u53e3\u70b9\u3002<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">mysite\/wsgi.py<\/mark>\uff1a\u517c\u5bb9WSGI\u7684web\u670d\u52a1\u5668\u5165\u53e3\u70b9\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728\u9879\u76ee\u4e2d\u65b0\u5efa\u4e00\u4e2a\u5e94\u7528<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">python manage.py startapp pools<\/mark><\/code><\/pre>\n\n\n\n<p>\u5b83\u4f1a\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">polls<\/mark><\/strong>\uff0c\u6587\u4ef6\u5939\u7ed3\u6784\u5e94\u8be5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>polls\/\n    __init__.py\n    admin.py\n    apps.py\n    migrations\/\n        __init__.py\n    models.py\n    tests.py\n    views.py<\/code><\/pre>\n\n\n\n<p>\u73b0\u5728\u5199\u7b2c\u4e00\u4e2a\u89c6\u56fe<strong>polls\/views.py<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from django.http import HttpResponse\n\ndef index(request):\n    return HttpResponse(\"Hello, world. You're at the polls index.\")<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u5728polls\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2aURLconf\u6587\u4ef6\u540d\u4e3a<strong>urls.py<\/strong>\uff0c\u5176\u5185\u5bb9\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from django.urls import path\n\nfrom . import views\n\nurlpatterns = &#91;\n    path(\"\", views.index, name=\"index\"),\n]<\/code><\/pre>\n\n\n\n<p>\u4e0b\u4e00\u6b65\u662f\u5728\u6839RULconf\u4e2d\u52a0\u5165poll.urls\u6a21\u5757\uff0c\u8fd9\u65f6\u9700\u8981\u5728<strong>mysite\/urls.py<\/strong>\u4e2d\u5bfc\u5165<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-light-green-cyan-color\">django.urls.include<\/mark>\u5934\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528include()\u628apoll.urls\u6a21\u5757\u52a0\u5165\u5230urlpatterns\u5217\u8868\u4e2d\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from django.contrib import admin\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">from django.urls import include, path<\/mark>\n\nurlpatterns = &#91;\n    path(\"polls\/\", include(\"polls.urls\")),\n    path(\"admin\/\", admin.site.urls),\n]<\/code><\/pre>\n\n\n\n<p>include()\u51fd\u6570\u5141\u8bb8\u5f15\u7528\u5176\u5b83\u7684URLconf\u6587\u4ef6\u3002\u5f53django\u9047\u5230include()\u51fd\u6570\u65f6\u4f1a\u622a\u53d6\u8bf7\u6c42\u5269\u4f59\u90e8\u5206\u53d1\u9001\u5230include()\u5305\u542b\u7684URLconf\u6587\u4ef6\u4e2d\u3002\uff08\u5982\uff1a\u8bf7\u6c42\u7684\u662f\/polls\/blog\/view\uff0c\u5728\u4e0a\u9762\u7684urlpatterns\u4e2d\u4f1a\u5339\u914d\u5230\u8bb0\u5f55\uff0c\u7136\u540e\u5c06\u201cpolls\/\u201d\u53bb\u6389\u540e\uff0c\u628ablog\/view\u4f20\u7ed9&#8221;polls.urls&#8221;\u5e94\u7528\u3002\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5b89\u88c5\u597ddjango\u6846\u67b6\u540e\uff0c\u4f7f\u7528django-admin startproject\u6765\u5efa\u7acb\u9879\u76ee\uff1a \u8fd9\u4f1a\u5728\u8fd0\u884c\u547d\u4ee4\u7684\u5f53\u524d\u76ee\u5f55\u5efa\u7acb\u4e00\u4e2amysite\u7684\u6587\u4ef6\u5939\u3002\u5728\u5efa\u91cc\u9879\u76ee&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=7382\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52,15],"tags":[],"class_list":["post-7382","post","type-post","status-publish","format-standard","hentry","category-django","category-python3"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7382","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=7382"}],"version-history":[{"count":3,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7382\/revisions"}],"predecessor-version":[{"id":7426,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7382\/revisions\/7426"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}