{"id":489,"date":"2023-02-19T19:01:16","date_gmt":"2023-02-19T11:01:16","guid":{"rendered":"https:\/\/www.gladguang.cn\/?p=489"},"modified":"2023-02-21T20:56:54","modified_gmt":"2023-02-21T12:56:54","slug":"django-%e7%ac%ac1%e8%8a%82%ef%bc%9a%e8%af%b7%e6%b1%82%e4%b8%8e%e7%9b%b8%e5%ba%94","status":"publish","type":"post","link":"https:\/\/www.gladguang.cn\/index.php\/2023\/02\/19\/django-%e7%ac%ac1%e8%8a%82%ef%bc%9a%e8%af%b7%e6%b1%82%e4%b8%8e%e7%9b%b8%e5%ba%94\/","title":{"rendered":"Django- \u7b2c1\u8282\uff1a\u8bf7\u6c42\u4e0e\u76f8\u5e94"},"content":{"rendered":"<h3>\u7b2c1\u8282\uff1a\u8bf7\u6c42\u4e0e\u76f8\u5e94<\/h3>\n<h4>1. \u521b\u5efa\u9879\u76ee<\/h4>\n<pre><code class=\"language-django line-numbers\">django-admin startproject mysite\n<\/code><\/pre>\n<ul>\n<li>\u5176\u4e2dmysite\u4e3a\u9879\u76ee\u540d\u79f0<\/li>\n<\/ul>\n<p>\u751f\u5b58\u7684\u6587\u4ef6\u76ee\u5f55\u5982\u4e0b\uff1a<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/cdn.jsdelivr.net\/gh\/gladguang\/photo\/markdown\/typora\/photo\/image-20230219163527186.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/cdn.jsdelivr.net\/gh\/gladguang\/photo\/markdown\/typora\/photo\/image-20230219163527186.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20230219163527186\" \/><\/div><\/p>\n<ul>\n<li>\u6700\u5916\u5c42\u7684:<code>file<\/code>: <code>mysite\/<\/code> \u6839\u76ee\u5f55\u53ea\u662f\u4f60\u9879\u76ee\u7684\u5bb9\u5668\uff0c Django \u4e0d\u5173\u5fc3\u5b83\u7684\u540d\u5b57\uff0c\u4f60\u53ef\u4ee5\u5c06\u5b83\u91cd\u547d\u540d\u4e3a\u4efb\u4f55\u4f60\u559c\u6b22\u7684\u540d\u5b57\u3002<\/li>\n<li><strong>manage.py<\/strong>: \u4e00\u4e2a\u8ba9\u4f60\u7528\u5404\u79cd\u65b9\u5f0f\u7ba1\u7406 Django \u9879\u76ee\u7684[\u547d\u4ee4\u884c\u5de5\u5177][\u547d\u4ee4\u884c\u5de5\u5177]\u3002<\/li>\n<li>\u91cc\u9762\u4e00\u5c42\u7684 <u><strong>mysite\/<\/strong><\/u> \u76ee\u5f55\u5305\u542b\u4f60\u7684\u9879\u76ee\uff0c\u5b83\u662f\u4e00\u4e2a\u7eaf Python \u5305\u3002\u5b83\u7684\u540d\u5b57\u5c31\u662f\u5f53\u4f60\u5f15\u7528\u5b83\u5185\u90e8\u4efb\u4f55\u4e1c\u897f\u65f6\u9700\u8981\u7528\u5230\u7684 Python \u5305\u540d\u3002 (\u6bd4\u5982 <code>mysite.urls<\/code>).<\/li>\n<li><strong><code>mysite\/__init__.py<\/code><\/strong>\uff1a\u4e00\u4e2a\u7a7a\u6587\u4ef6\uff0c\u544a\u8bc9 Python \u8fd9\u4e2a\u76ee\u5f55\u5e94\u8be5\u88ab\u8ba4\u4e3a\u662f\u4e00\u4e2a Python \u5305\u3002<\/li>\n<li><strong><em><code>mysite\/settings.py<\/code><\/em><\/strong>\uff1aDjango \u9879\u76ee\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/li>\n<li><strong><em><code>mysite\/urls.py<\/code><\/em><\/strong>\uff1aDjango \u9879\u76ee\u7684 URL \u58f0\u660e\uff0c\u5c31\u50cf\u4f60\u7f51\u7ad9\u7684\u201c\u76ee\u5f55\u3002<\/li>\n<li><strong><em><code>mysite\/asgi.py<\/code><\/em><\/strong>\uff1a\u4f5c\u4e3a\u4f60\u7684\u9879\u76ee\u7684\u8fd0\u884c\u5728 ASGI \u517c\u5bb9\u7684 Web \u670d\u52a1\u5668\u4e0a\u7684\u5165\u53e3\u3002<\/li>\n<li><strong><em><code>mysite\/wsgi.py<\/code><\/em><\/strong>\uff1a\u4f5c\u4e3a\u4f60\u7684\u9879\u76ee\u7684\u8fd0\u884c\u5728 WSGI \u517c\u5bb9\u7684Web\u670d\u52a1\u5668\u4e0a\u7684\u5165\u53e3\u3002<\/li>\n<\/ul>\n<h4>2. \u7b80\u5355\u8fd0\u884c<\/h4>\n<p>\u8fdb\u5165 <strong><em><code>mysite<\/code><\/em><\/strong> \u76ee\u5f55\u4e0b\uff0c\u8fd0\u884c\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-django line-numbers\">python manage.py runserver 0.0.0.0:8000\n<\/code><\/pre>\n<p>\u4f1a\u6709\u5982\u4e0b\u8f93\u51fa<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='Django\u5b66\u4e60\u7b14\u8bb0\/image-20230219164952488.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"Django\u5b66\u4e60\u7b14\u8bb0\/image-20230219164952488.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20230219164952488\" \/><\/div><\/p>\n<ul>\n<li>\u670d\u52a1\u5668\u73b0\u5728\u6b63\u5728\u8fd0\u884c\uff0c\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee http:\/\/127.0.0.1:8000\/ \u3002\u4f60\u5c06\u770b\u5230\u4e00\u4e2a\u201c\u795d\u8d3a\u201d\u9875\u9762\uff0c\u6709\u4e00\u53ea\u706b\u7bad\u6b63\u5728\u53d1\u5c04\u3002\u4f60\u6210\u529f\u4e86\uff01<\/li>\n<\/ul>\n<p>ps: \u7528\u4e8e\u5f00\u53d1\u7684\u670d\u52a1\u5668\u5728\u9700\u8981\u7684\u60c5\u51b5\u4e0b\u4f1a\u5bf9\u6bcf\u4e00\u6b21\u7684\u8bbf\u95ee\u8bf7\u6c42\u91cd\u65b0\u8f7d\u5165\u4e00\u904d Python \u4ee3\u7801\u3002\u6240\u4ee5\u4f60\u4e0d\u9700\u8981\u4e3a\u4e86\u8ba9\u4fee\u6539\u7684\u4ee3\u7801\u751f\u6548\u800c\u9891\u7e41\u7684\u91cd\u65b0\u542f\u52a8\u670d\u52a1\u5668\u3002\u7136\u800c\uff0c\u4e00\u4e9b\u52a8\u4f5c\uff0c\u6bd4\u5982<strong>\u6dfb\u52a0\u65b0\u6587\u4ef6<\/strong>\uff0c\u5c06\u4e0d\u4f1a\u89e6\u53d1\u81ea\u52a8\u91cd\u65b0\u52a0\u8f7d\uff0c\u8fd9\u65f6\u4f60\u5f97\u81ea\u5df1<strong>\u624b\u52a8\u91cd\u542f\u670d\u52a1\u5668<\/strong>\u3002<\/p>\n<h4>3.\u521b\u5efa\u6295\u7968\u5e94\u7528<\/h4>\n<p><strong>mysite<\/strong> \u8fd9\u4e2a\u9879\u76ee\u914d\u7f6e\u597d\u4e86<\/p>\n<p>\u5728 Django \u4e2d\uff0c\u6bcf\u4e00\u4e2a\u5e94\u7528\u90fd\u662f\u4e00\u4e2a Python \u5305\uff0c\u5e76\u4e14\u9075\u5faa\u7740\u76f8\u540c\u7684\u7ea6\u5b9a\u3002Django \u81ea\u5e26\u4e00\u4e2a\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u4f60\u751f\u6210\u5e94\u7528\u7684\u57fa\u7840\u76ee\u5f55\u7ed3\u6784\uff0c\u8fd9\u6837\u4f60\u5c31\u80fd\u4e13\u5fc3\u5199\u4ee3\u7801\uff0c\u800c\u4e0d\u662f\u521b\u5efa\u76ee\u5f55\u4e86\u3002<\/p>\n<pre><code class=\"language-markdown line-numbers\">\u9879\u76ee VS \u5e94\u7528\n\n\u9879\u76ee\u548c\u5e94\u7528\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u5e94\u7528\u662f\u4e00\u4e2a\u4e13\u95e8\u505a\u67d0\u4ef6\u4e8b\u7684\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f\u2014\u2014\u6bd4\u5982\u535a\u5ba2\u7cfb\u7edf\uff0c\u6216\u8005\u516c\u5171\u8bb0\u5f55\u7684\u6570\u636e\u5e93\uff0c\u6216\u8005\u5c0f\u578b\u7684\u6295\u7968\u7a0b\u5e8f\u3002\u9879\u76ee\u5219\u662f\u4e00\u4e2a\u7f51\u7ad9\u4f7f\u7528\u7684\u914d\u7f6e\u548c\u5e94\u7528\u7684\u96c6\u5408\u3002\u9879\u76ee\u53ef\u4ee5\u5305\u542b\u5f88\u591a\u4e2a\u5e94\u7528\u3002\u5e94\u7528\u53ef\u4ee5\u88ab\u5f88\u591a\u4e2a\u9879\u76ee\u4f7f\u7528\u3002\n<\/code><\/pre>\n<p>\u5e94\u7528\u53ef\u4ee5\u5b58\u653e\u5728\u4efb\u4f55 <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.python.org\/3\/tutorial\/modules.html#tut-searchpath\">Python \u8def\u5f84<\/a> \u4e2d\u5b9a\u4e49\u7684\u8def\u5f84\u3002\u5728\u8fd9\u4e2a\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u5728\u4f60\u7684 <code>manage.py<\/code> \u540c\u7ea7\u76ee\u5f55\u4e0b\u521b\u5efa\u6295\u7968\u5e94\u7528\u3002\u8fd9\u6837\u5b83\u5c31\u53ef\u4ee5\u4f5c\u4e3a\u9876\u7ea7\u6a21\u5757\u5bfc\u5165\uff0c\u800c\u4e0d\u662f <code>mysite<\/code> \u7684\u5b50\u6a21\u5757\u3002<\/p>\n<p>\u8bf7\u786e\u5b9a\u4f60\u73b0\u5728\u5904\u4e8e <code>manage.py<\/code> \u6240\u5728\u7684\u76ee\u5f55\u4e0b\uff0c\u7136\u540e\u8fd0\u884c\u8fd9\u884c\u547d\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u5e94\u7528\uff1a<\/p>\n<pre><code class=\"language-django line-numbers\">python manage.py startapp polls\n<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/cdn.jsdelivr.net\/gh\/gladguang\/photo\/markdown\/typora\/photo\/image-20230219170617486.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/cdn.jsdelivr.net\/gh\/gladguang\/photo\/markdown\/typora\/photo\/image-20230219170617486.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20230219170617486\" \/><\/div><\/p>\n<h4>4. \u7f16\u5199\u7b2c\u4e00\u4e2a\u89c6\u56fe<\/h4>\n<p>\u5f00\u59cb\u7f16\u5199\u7b2c\u4e00\u4e2a\u89c6\u56fe\u5427\u3002\u6253\u5f00 <code>polls\/views.py<\/code>\uff0c\u628a\u4e0b\u9762\u8fd9\u4e9b Python \u4ee3\u7801\u8f93\u5165\u8fdb\u53bb\uff1a<\/p>\n<pre><code class=\"line-numbers\">from django.http import HttpResponse\n\n\n# Create your views here.\ndef index(req):\n    return HttpResponse('&lt;h1 type=\"color: red\"&gt;Hello my friends!&lt;\/h1&gt;')\n\n<\/code><\/pre>\n<p>\u5982\u679c\u60f3\u770b\u89c1\u6548\u679c\uff0c\u6211\u4eec\u9700\u8981\u5c06\u4e00\u4e2a URL \u6620\u5c04\u5230\u5b83\u2014\u2014\u8fd9\u5c31\u662f\u6211\u4eec\u9700\u8981 URLconf \u7684\u539f\u56e0\u4e86\u3002<\/p>\n<p>\u4e3a\u4e86\u521b\u5efa URLconf\uff0c\u5728 polls \u76ee\u5f55\u91cc\u65b0\u5efa\u4e00\u4e2a <code>urls.py<\/code> \u6587\u4ef6\u3002\u4f60\u7684\u5e94\u7528\u76ee\u5f55\u73b0\u5728\u770b\u8d77\u6765\u5e94\u8be5\u662f\u8fd9\u6837\uff1a<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/cdn.jsdelivr.net\/gh\/gladguang\/photo\/markdown\/typora\/photo\/image-20230219171234188-16769806682091.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/cdn.jsdelivr.net\/gh\/gladguang\/photo\/markdown\/typora\/photo\/image-20230219171234188-16769806682091.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20230219171234188\" \/><\/div><\/p>\n<p>\u51fd\u6570 <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/urls\/#django.urls.include\"><code>include()<\/code><\/a> \u5141\u8bb8\u5f15\u7528\u5176\u5b83 URLconfs\u3002\u6bcf\u5f53 Django \u9047\u5230 <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/urls\/#django.urls.include\"><code>include()<\/code><\/a> \u65f6\uff0c\u5b83\u4f1a\u622a\u65ad\u4e0e\u6b64\u9879\u5339\u914d\u7684 URL \u7684\u90e8\u5206\uff0c\u5e76\u5c06\u5269\u4f59\u7684\u5b57\u7b26\u4e32\u53d1\u9001\u5230 URLconf \u4ee5\u4f9b\u8fdb\u4e00\u6b65\u5904\u7406\u3002<\/p>\n<p>\u6211\u4eec\u8bbe\u8ba1 <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/urls\/#django.urls.include\"><code>include()<\/code><\/a> \u7684\u7406\u5ff5\u662f\u4f7f\u5176\u53ef\u4ee5\u5373\u63d2\u5373\u7528\u3002\u56e0\u4e3a\u6295\u7968\u5e94\u7528\u6709\u5b83\u81ea\u5df1\u7684 URLconf( <code>polls\/urls.py<\/code> )\uff0c\u4ed6\u4eec\u80fd\u591f\u88ab\u653e\u5728 &#8220;\/polls\/&#8221; \uff0c &#8220;\/fun_polls\/&#8221; \uff0c&#8221;\/content\/polls\/&#8221;\uff0c\u6216\u8005\u5176\u4ed6\u4efb\u4f55\u8def\u5f84\u4e0b\uff0c\u8fd9\u4e2a\u5e94\u7528\u90fd\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<hr \/>\n<p>\u51fd\u6570 <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/urls\/#django.urls.path\"><code>path()<\/code><\/a> \u5177\u6709\u56db\u4e2a\u53c2\u6570\uff0c\u4e24\u4e2a\u5fc5\u987b\u53c2\u6570\uff1a<code>route<\/code> \u548c <code>view<\/code>\uff0c\u4e24\u4e2a\u53ef\u9009\u53c2\u6570\uff1a<code>kwargs<\/code> \u548c <code>name<\/code>\u3002\u73b0\u5728\uff0c\u662f\u65f6\u5019\u6765\u7814\u7a76\u8fd9\u4e9b\u53c2\u6570\u7684\u542b\u4e49\u4e86\u3002<\/p>\n<h5><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/urls\/#django.urls.path\"><code>path()<\/code><\/a> \u53c2\u6570\uff1a <code>route<\/code><\/h5>\n<p><code>route<\/code> \u662f\u4e00\u4e2a\u5339\u914d URL \u7684\u51c6\u5219\uff08\u7c7b\u4f3c\u6b63\u5219\u8868\u8fbe\u5f0f\uff09\u3002\u5f53 Django \u54cd\u5e94\u4e00\u4e2a\u8bf7\u6c42\u65f6\uff0c\u5b83\u4f1a\u4ece <code>urlpatterns<\/code> \u7684\u7b2c\u4e00\u9879\u5f00\u59cb\uff0c\u6309\u987a\u5e8f\u4f9d\u6b21\u5339\u914d\u5217\u8868\u4e2d\u7684\u9879\uff0c\u76f4\u5230\u627e\u5230\u5339\u914d\u7684\u9879\u3002<\/p>\n<p>\u8fd9\u4e9b\u51c6\u5219\u4e0d\u4f1a\u5339\u914d GET \u548c POST \u53c2\u6570\u6216\u57df\u540d\u3002\u4f8b\u5982\uff0cURLconf \u5728\u5904\u7406\u8bf7\u6c42 <code>https:\/\/www.example.com\/myapp\/<\/code> \u65f6\uff0c\u5b83\u4f1a\u5c1d\u8bd5\u5339\u914d <code>myapp\/<\/code> \u3002\u5904\u7406\u8bf7\u6c42 <code>https:\/\/www.example.com\/myapp\/?page=3<\/code> \u65f6\uff0c\u4e5f\u53ea\u4f1a\u5c1d\u8bd5\u5339\u914d <code>myapp\/<\/code>\u3002<\/p>\n<h5><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/urls\/#django.urls.path\"><code>path()<\/code><\/a> \u53c2\u6570\uff1a <code>view<\/code><\/h5>\n<p>\u5f53 Django \u627e\u5230\u4e86\u4e00\u4e2a\u5339\u914d\u7684\u51c6\u5219\uff0c\u5c31\u4f1a\u8c03\u7528\u8fd9\u4e2a\u7279\u5b9a\u7684\u89c6\u56fe\u51fd\u6570\uff0c\u5e76\u4f20\u5165\u4e00\u4e2a <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/request-response\/#django.http.HttpRequest\"><code>HttpRequest<\/code><\/a> \u5bf9\u8c61\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u88ab\u201c\u6355\u83b7\u201d\u7684\u53c2\u6570\u4ee5\u5173\u952e\u5b57\u53c2\u6570\u7684\u5f62\u5f0f\u4f20\u5165\u3002\u7a0d\u540e\uff0c\u6211\u4eec\u4f1a\u7ed9\u51fa\u4e00\u4e2a\u4f8b\u5b50\u3002<\/p>\n<h5><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/urls\/#django.urls.path\"><code>path()<\/code><\/a> \u53c2\u6570\uff1a <code>kwargs<\/code><\/h5>\n<p>\u4efb\u610f\u4e2a\u5173\u952e\u5b57\u53c2\u6570\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u5178\u4f20\u9012\u7ed9\u76ee\u6807\u89c6\u56fe\u51fd\u6570\u3002\u672c\u6559\u7a0b\u4e2d\u4e0d\u4f1a\u4f7f\u7528\u8fd9\u4e00\u7279\u6027\u3002<\/p>\n<h5><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/4.1\/ref\/urls\/#django.urls.path\"><code>path()<\/code><\/a> \u53c2\u6570\uff1a <code>name<\/code><\/h5>\n<p>\u4e3a\u4f60\u7684 URL \u53d6\u540d\u80fd\u4f7f\u4f60\u5728 Django \u7684\u4efb\u610f\u5730\u65b9\u552f\u4e00\u5730\u5f15\u7528\u5b83\uff0c\u5c24\u5176\u662f\u5728\u6a21\u677f\u4e2d\u3002\u8fd9\u4e2a\u6709\u7528\u7684\u7279\u6027\u5141\u8bb8\u4f60\u53ea\u6539\u4e00\u4e2a\u6587\u4ef6\u5c31\u80fd\u5168\u5c40\u5730\u4fee\u6539\u67d0\u4e2a URL \u6a21\u5f0f\u3002<\/p>\n<p>\u4e86\u89e3\u4e86\u57fa\u672c\u7684\u8bf7\u6c42\u548c\u54cd\u5e94\u6d41\u7a0b\u540e\uff0c\u8bf7\u9605\u8bfb <a class=\"wp-editor-md-post-content-link\" href=\"\/index.php\/2023\/02\/19\/django-%e7%ac%ac2%e8%8a%82%ef%bc%9a%e6%a8%a1%e5%9e%8b%e4%b8%8e%e7%ab%99%e7%82%b9%e7%ae%a1%e7%90%86\/\">Django\u7684\u7b2c 2 \u90e8\u5206<\/a> \u5f00\u59cb\u4f7f\u7528\u6570\u636e\u5e93.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c1\u8282\uff1a\u8bf7\u6c42\u4e0e\u76f8\u5e94 1. \u521b\u5efa\u9879\u76ee django-admin startproject mysite \u5176\u4e2dmy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,64,80,6,76],"tags":[81,23,82,32],"class_list":["post-489","post","type-post","status-publish","format-standard","hentry","category-59","category-64","category-django","category-python","category-programming-language","tag-django","tag-python","tag-web","tag-32"],"_links":{"self":[{"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/posts\/489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/comments?post=489"}],"version-history":[{"count":5,"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/posts\/489\/revisions"}],"predecessor-version":[{"id":501,"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/posts\/489\/revisions\/501"}],"wp:attachment":[{"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/media?parent=489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/categories?post=489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gladguang.cn\/index.php\/wp-json\/wp\/v2\/tags?post=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}