{"id":28381,"date":"2023-03-23T09:36:43","date_gmt":"2023-03-10T11:48:11","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/"},"modified":"2025-08-12T07:51:33","modified_gmt":"2025-08-11T23:51:33","slug":"%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/","title":{"rendered":"\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c"},"content":{"rendered":"<p>\u6211\u5728\u8fd9\u4e2a\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u4e86CRUD\u529f\u80fd\u3002\u4f7f\u7528Django\u663e\u793aMariaDB\u7684\u6570\u636e\u8868\u3002<\/p>\n<p>\u8fd9\u662fDjango\u7684\u4ee3\u7801\u3002<br \/>\nekzemplaro\/django_mariadb_city<\/p>\n<p>\u5e94\u7528\u7a0b\u5e8f\u7684\u7ed3\u6784<\/p>\n<pre class=\"post-pre\"><code>$ tree city -I '_*'\r\ncity\r\n\u251c\u2500\u2500 admin.py\r\n\u251c\u2500\u2500 apps.py\r\n\u251c\u2500\u2500 forms.py\r\n\u251c\u2500\u2500 migrations\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 0001_initial.py\r\n\u251c\u2500\u2500 models.py\r\n\u251c\u2500\u2500 static\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 city\r\n\u2502\u00a0\u00a0     \u2514\u2500\u2500 css\r\n\u2502\u00a0\u00a0         \u2514\u2500\u2500 city.css\r\n\u251c\u2500\u2500 templates\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 city\r\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 create.html\r\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 delete.html\r\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 edit.html\r\n\u2502\u00a0\u00a0     \u2514\u2500\u2500 index.html\r\n\u251c\u2500\u2500 tests.py\r\n\u251c\u2500\u2500 urls.py\r\n\u2514\u2500\u2500 views.py\r\n<\/code><\/pre>\n<p>1) \u4eceGitHub\u514b\u9686<\/p>\n<pre class=\"post-pre\"><code>git clone https:\/\/github.com\/ekzemplaro\/django_mariadb_city\r\n<\/code><\/pre>\n<p>2) \u5b89\u88c5\u6240\u9700\u7684\u5e93<\/p>\n<pre class=\"post-pre\"><code><span class=\"nb\">sudo <\/span>pip3 <span class=\"nb\">install <\/span>django-environ\r\n<\/code><\/pre>\n<p>\u521b\u5efa.env \u6587\u4ef6<\/p>\n<pre class=\"post-pre\"><code>DB_USER=\"django\"\r\nDB_PASSWORD=\"tiger123\"\r\nDB_NAME=\"django_city\"\r\n<\/code><\/pre>\n<p>4) \u521b\u5efa\u6570\u636e\u5e93<br \/>\n\u7528\u6237 django<br \/>\n\u5bc6\u7801 tiger123<br \/>\n\u6570\u636e\u5e93 django_city<\/p>\n<pre class=\"post-pre\"><code>mysql&gt; create database django_city;\r\nmysql&gt; grant all on django_city.* to django@localhost;\r\n<\/code><\/pre>\n<p>5) \u79fb\u6c11<\/p>\n<pre class=\"post-pre\"><code><span class=\"nb\">cd <\/span>prog01\r\npython manage.py migrate\r\n<\/code><\/pre>\n<p>\u5c06\u6570\u636e\u5b58\u5165\u6570\u636e\u5e93\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nb\">cd <\/span>data\r\n.\/go_restore.sh\r\n<\/code><\/pre>\n<p>7) \u542f\u52a8\u5f00\u53d1\u670d\u52a1\u5668<\/p>\n<pre class=\"post-pre\"><code>python manage.py runserver\r\n<\/code><\/pre>\n<p>8) \u8bbf\u95ee http:\/\/127.0.0.1:8000\/city\/<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657cfc1437434c4406bbf8fa\/19-0.png\" alt=\"city_jan2201.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657cfc1437434c4406bbf8fa\/20-0.png\" alt=\"city_jan2202.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657cfc1437434c4406bbf8fa\/21-0.png\" alt=\"city_jan2203.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657cfc1437434c4406bbf8fa\/22-0.png\" alt=\"city_jan2204.png\" \/><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u5728\u8fd9\u4e2a\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u4e86CRUD\u529f\u80fd\u3002\u4f7f\u7528Django\u663e\u793aMariaDB\u7684\u6570\u636e\u8868\u3002 \u8fd9\u662fDjango\u7684\u4ee3\u7801\u3002 ek [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[227],"class_list":["post-28381","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-227"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u5173\u4e8e\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u7684\u6280\u672f\u6587\u7ae0\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528-django-\u8fdb\u884c-mariadb-\u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\" \/>\n<meta property=\"og:description\" content=\"\u5173\u4e8e\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u7684\u6280\u672f\u6587\u7ae0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528-django-\u8fdb\u884c-mariadb-\u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-10T11:48:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-11T23:51:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657cfc1437434c4406bbf8fa\/19-0.png\" \/>\n<meta name=\"author\" content=\"\u5b87, \u534e\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u5b87, \u534e\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/\",\"name\":\"\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-03-10T11:48:11+00:00\",\"dateModified\":\"2025-08-11T23:51:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/513018e4e121d3add1b7c5de8be21458\"},\"description\":\"\u5173\u4e8e\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u7684\u6280\u672f\u6587\u7ae0\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/513018e4e121d3add1b7c5de8be21458\",\"name\":\"\u5b87, \u534e\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/63cd45cbc05a35fc4ff7637a163c83c4962ef58d27472726c3a3e0c9c5194f0f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/63cd45cbc05a35fc4ff7637a163c83c4962ef58d27472726c3a3e0c9c5194f0f?s=96&d=mm&r=g\",\"caption\":\"\u5b87, \u534e\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yuhua\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c - Blog - Silicon Cloud","description":"\u5173\u4e8e\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u7684\u6280\u672f\u6587\u7ae0","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528-django-\u8fdb\u884c-mariadb-\u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c","og_description":"\u5173\u4e8e\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u7684\u6280\u672f\u6587\u7ae0","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528-django-\u8fdb\u884c-mariadb-\u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-03-10T11:48:11+00:00","article_modified_time":"2025-08-11T23:51:33+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657cfc1437434c4406bbf8fa\/19-0.png"}],"author":"\u5b87, \u534e","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u5b87, \u534e","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/","name":"\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-03-10T11:48:11+00:00","dateModified":"2025-08-11T23:51:33+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/513018e4e121d3add1b7c5de8be21458"},"description":"\u5173\u4e8e\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u7684\u6280\u672f\u6587\u7ae0","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528 Django \u8fdb\u884c MariaDB \u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/513018e4e121d3add1b7c5de8be21458","name":"\u5b87, \u534e","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/63cd45cbc05a35fc4ff7637a163c83c4962ef58d27472726c3a3e0c9c5194f0f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/63cd45cbc05a35fc4ff7637a163c83c4962ef58d27472726c3a3e0c9c5194f0f?s=96&d=mm&r=g","caption":"\u5b87, \u534e"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yuhua\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8-django-%e8%bf%9b%e8%a1%8c-mariadb-%e7%9a%84%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/28381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=28381"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/28381\/revisions"}],"predecessor-version":[{"id":87389,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/28381\/revisions\/87389"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=28381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=28381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=28381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}