{"id":2065,"date":"2023-04-01T21:36:47","date_gmt":"2023-04-01T13:36:47","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2065"},"modified":"2023-04-07T06:04:01","modified_gmt":"2023-04-06T22:04:01","slug":"getting-started-with-python-web-framework-django","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/01\/getting-started-with-python-web-framework-django\/","title":{"rendered":"Python Web\u6846\u67b6Django\u5165\u95e8"},"content":{"rendered":"<h2>\u5b89\u88c5\u542f\u52a8<\/h2>\n<p>Python\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/www.python.org\/downloads\/\">https:\/\/www.python.org\/downloads\/<\/a><br \/>\nDjango\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/www.djangoproject.com\/download\/\">https:\/\/www.djangoproject.com\/download\/<\/a><\/p>\n<p><!-- more --><\/p>\n<pre><code>> pip install Django==3.0.7  #pip\u65b9\u5f0f\u5b89\u88c5\n> django-admin startproject HelloWorld  #\u521b\u5efa\u9879\u76ee\n> cd HelloWorld\n> python manage.py runserver 0.0.0.0:8000  #\u542f\u52a8\u670d\u52a1<\/code><\/pre>\n<h2>\u6570\u636e\u5e93\u53ca\u7528\u6237<\/h2>\n<p>\u521b\u5efa\u9ed8\u8ba4\u5e93<\/p>\n<pre><code>python manage.py migrate<\/code><\/pre>\n<p>\u521b\u5efa\u9ed8\u8ba4\u8d85\u7ea7\u7528\u6237<\/p>\n<pre><code>python manage.py createsuperuser<\/code><\/pre>\n<h2>\u89c6\u56fe\u548c URL \u914d\u7f6e<\/h2>\n<p>\u65b0\u5efa\u6587\u4ef6<code>HelloWorld\/HelloWorld\/views.py<\/code>\uff1a<\/p>\n<pre><code class=\"language-python\">from django.http import HttpResponse\n\ndef hello(request):\n    return HttpResponse(&quot;Hello world!&quot;)<\/code><\/pre>\n<p>\u7ed1\u5b9a URL \u4e0e\u89c6\u56fe\u51fd\u6570\u3002\u7f16\u8f91\u6587\u4ef6<code>HelloWorld\/HelloWorld\/urls.py<\/code>\uff1a<\/p>\n<pre><code class=\"language-python\">from django.contrib import admin\nfrom django.urls import path\nfrom . import views\n\nurlpatterns = [\n    path(&#039;admin\/&#039;, admin.site.urls),\n    path(&#039;hello\/&#039;, views.hello),\n    path(&#039;&#039;, views.hello),\n]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5\u542f\u52a8 Python\uff1ahttps:\/\/www.python.org\/downloads\/ Django\uff1aht [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[522],"class_list":["post-2065","post","type-post","status-publish","format-standard","hentry","category-python","tag-django"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2065"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2065\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}