{"id":2719,"date":"2016-06-13T21:05:17","date_gmt":"2016-06-13T13:05:17","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2719"},"modified":"2016-06-13T21:05:17","modified_gmt":"2016-06-13T13:05:17","slug":"%e5%9c%a8django%e9%a1%b9%e7%9b%ae%e4%b8%ad%e4%bd%bf%e7%94%a8bootstrap%e6%a8%a1%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2719.html","title":{"rendered":"\u5728Django\u9879\u76ee\u4e2d\u4f7f\u7528Bootstrap\u6a21\u677f"},"content":{"rendered":"<p>=Start=<\/p>\n<h5>\u7f18\u7531\uff1a<\/h5>\n<p>\u8fd9\u662f\u4e00\u4e2a\u770b\u8138\u7684\u793e\u4f1a\uff0c\u5bf9\u4e8e\u5f00\u53d1\u6765\u8bf4\u4e5f\u662f\u8fd9\u6837\uff1a\u5373\u4fbf\u540e\u53f0\u903b\u8f91\u505a\u7684\u5c4c\u70b8\u5929\uff0c\u4f46\u662f\u5982\u679c\u6ca1\u6709\u4e00\u4e2a\u6f02\u4eae\u7684\u524d\u7aef\u5c55\u793a\u754c\u9762\uff0c\u5bf9\u4e8e\u522b\u4eba\u6765\u8bf4\uff0c\u8fd8\u662f\u592alow\u4e86\u2026\u2026\u4ed6\u4eec\u624d\u4e0d\u4f1a\u7ba1\u4f60\u82b1\u4e86\u591a\u5c11\u7cbe\u529b\u53bb\u89e3\u51b3\u540e\u7aef\u590d\u6742\u7684\u903b\u8f91\uff0c\u53ea\u4f1a\u4e22\u4e0b\u4e00\u53e5\u2014\u2014\u8fd9\u4e0d\u662f\u6211\u60f3\u8981\u7684\u3002<\/p>\n<p>\u6ca1\u529e\u6cd5\uff0c\u5b66\u4e60\u4e00\u4e0b\u5982\u4f55\u7f8e\u5316\u524d\u7aef\u754c\u9762\u5427\u3002\u5bf9\u4e8e\u4eba\u624b\u4e0d\u8db3\u7684\u540e\u7aef\u5f00\u53d1\u56e2\u961f\u6765\u8bf4\uff0c\u82b1\u65f6\u95f4\u53bb\u5b66\u4e60CSS\u3001JavaScript\u3001PS\u7b49\u6280\u672f\uff0c\u7136\u540e\u81ea\u5df1\u8bbe\u8ba1\u524d\u7aef\u754c\u9762\uff0c\u8fd9\u663e\u7136\u662f\u4e0d\u73b0\u5b9e\u7684\uff1b\u4e00\u4e2a\u6bd4\u8f83\u9760\u8c31\u7684\u529e\u6cd5\u5c31\u662f\uff0c\u9009\u7528\u7f51\u4e0a\u73b0\u6210\u7684Bootstrap\u6a21\u677f\uff0c\u7136\u540e\u5728\u5176\u57fa\u7840\u4e0a\u6309\u9700\u4fee\u6539\u3002\u4e0b\u9762\u5c31\u662f\u5728\u4e00\u4e2aDjango\u9879\u76ee\u4e2d\u5957\u7528Bootstrap\u6a21\u677f\u7684\u8fc7\u7a0b\u8bb0\u5f55\u3002<\/p>\n<h5>\u6b63\u6587\uff1a<\/h5>\n<h6>1.Django\u73af\u5883\u642d\u5efa<\/h6>\n<p>\u6211\u7684\u7cfb\u7edf\u662fCentOS 6.5\uff0c\u7528\u7684Python\u662f\u81ea\u5df1\u7f16\u8bd1\u5b89\u88c5\u7684Python 2.7\uff0cPIP\u4e5f\u662f\u624b\u52a8\u5b89\u88c5\u7684\uff0cDjango\u7684\u642d\u5efa\u8fc7\u7a0b\u4e3b\u8981\u53c2\u8003\uff1a<a href=\"http:\/\/www.ziqiangxuetang.com\/django\/django-install.html\">Django \u73af\u5883\u642d\u5efa<\/a>\uff0c\u662f\u7528\u7684PIP\u65b9\u5f0f\u8fdb\u884cDjango\u7684\u5b89\u88c5\uff0c\u4e0b\u9762\u4e3b\u8981\u8bb0\u5f55\u4e00\u4e0b\u5728\u6b64\u8fc7\u7a0b\u4e2d\u78b0\u5230\u7684\u95ee\u9898\u3002<\/p>\n<p>\u95ee\u9898\u4e00\uff1adjango.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0bPython\u662f\u4f1a\u5b89\u88c5 sqlite3 \u6a21\u5757\u7684\uff0c\u4f46\u662f\uff0c\u5982\u679c\u4f60\u6ca1\u6709 sqlite-devel \u73af\u5883\u5c31\u4e0d\u884c\uff0c\u6240\u4ee5\u9700\u8981\u5148\u5b89\u88c5 sqlite-devel \uff1a<br \/>\n$ sudo yum install sqlite-devel<\/p>\n<p>\u7136\u540e\u91cd\u65b0\u7f16\u8bd1\u5b89\u88c5 Python \uff1a\u300c.\/configure &amp;&amp; make &amp;&amp; sudo make install\u300d\u5373\u53ef\u3002<\/p>\n<h6>2.Django\u57fa\u672c\u547d\u4ee4\u4e0e\u6a21\u677f<\/h6>\n<pre class=\"lang:default decode:true\" title=\"Django\u57fa\u672c\u547d\u4ee4\">#1. \u65b0\u5efa\u4e00\u4e2a django project\ndjango-admin.py startproject ui_project\ncd ui_project\/\n\n#2. \u65b0\u5efa app\ndjango-admin.py startapp ui_app\n\nvim ui_project\/settings.py #\u5c06\u65b0\u5b9a\u4e49\u7684app\u540d\u79f0(ui_app)\u52a0\u5230settings.py\u4e2d\u7684INSTALL_APPS\u4e2d\nvim ui_app\/views.py    #\u5b9a\u4e49\u89c6\u56fe\u51fd\u6570\uff08\u8bbf\u95ee\u9875\u9762\u65f6\u7684\u5185\u5bb9\uff09\nvim ui_project\/urls.py #\u5b9a\u4e49\u89c6\u56fe\u51fd\u6570\u76f8\u5173\u7684URL[\u5373\uff1a\u8bbf\u95ee\u4ec0\u4e48\u7f51\u5740\u5bf9\u5e94\u4ec0\u4e48\u5185\u5bb9]\n\n#3. \u540c\u6b65\u6570\u636e\u5e93\npython manage.py makemigrations\npython manage.py migrate\n\n#4. \u8fd0\u884c\u6d4b\u8bd5\npython manage.py runserver\npython manage.py runserver 0.0.0.0:8080<\/pre>\n<pre class=\"lang:default decode:true\" title=\"Django\u6a21\u677f\"># http:\/\/www.ziqiangxuetang.com\/django\/django-template.html\n# http:\/\/www.ziqiangxuetang.com\/django\/django-template2.html\n\n#\u6b65\u9aa4\u4e00\n$ vim ui_app\/views.py    #\u5b9a\u4e49\u89c6\u56fe\u51fd\u6570\uff08\u8bbf\u95ee\u9875\u9762\u65f6\u7684\u5185\u5bb9\uff09\n    from django.shortcuts import render\n    def index(request):\n        return render(request, 'index.html')\n\n#\u6b65\u9aa4\u4e8c\n$ mkdir -p ui_app\/templates #\u521b\u5efatemplates\u76ee\u5f55\u7528\u4e8e\u5b58\u653eHTML\u6a21\u677f\u6587\u4ef6\n$ echo \"Hello, Django!\" &gt; ui_app\/templates\/index.html   #\u7f16\u8f91HTML\u6a21\u677f\u6587\u4ef6\n\n#\u6b65\u9aa4\u4e09\n$ vim ui_project\/urls.py #\u5b9a\u4e49\u89c6\u56fe\u51fd\u6570\u76f8\u5173\u7684URL\n    urlpatterns = [\n        url(r'^$', ui_app.views.index, name='index'),\n        url(r'^admin\/', include(admin.site.urls)),\n    ]<\/pre>\n<h6>3.\u5957\u7528Bootstrap\u6a21\u677f<\/h6>\n<p>\u5728GitHub\u4e0a\u9762\u6709\u4e24\u4e2a\u5f00\u6e90\u7684\u9879\u76ee\u7528\u6765\u6574\u5408Django\u548cBootstrap\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/dyve\/django-bootstrap-toolkit\">https:\/\/github.com\/dyve\/django-bootstrap-toolkit<\/a> #\u5bf9\u5e94bootstrap 2.0<\/li>\n<li><a href=\"https:\/\/github.com\/dyve\/django-bootstrap3\">https:\/\/github.com\/dyve\/django-bootstrap3<\/a> #\u5bf9\u5e94bootstrap 3.0<\/li>\n<\/ul>\n<p>\u4f46\u662f\u4f7f\u7528\u8fd9\u4e9b\u63d2\u4ef6\u7684\u8bdd\uff0c\u4f1a\u589e\u52a0\u989d\u5916\u7684\u5b66\u4e60\u6210\u672c\uff0c\u6240\u4ee5\u6211\u504f\u5411\u4e8e\u4f7f\u7528\u539f\u751f\u7684\u65b9\u5f0f\u8c03\u7528Bootstrap\u6a21\u677f\u3002<\/p>\n<p><strong><span style=\"color: #0000ff;\">\u56e0\u4e3aBootstrap\u5c31\u662f\u4e00\u5806css\u548cjs\u4ee5\u53ca\u5b57\u4f53\u6587\u4ef6\uff0c\u5e76\u4e14\u5c5e\u4e8e\u9759\u6001\u8d44\u6e90\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u9700\u8981\u914d\u7f6e\u597dDjango\u7684\u9759\u6001\u6587\u4ef6\u8bbf\u95ee\u8def\u5f84\uff0c\u80fd\u591f\u8ba9templates\u91cc\u9762\u7684\u4ee3\u7801\u8bbf\u95ee\u5230Bootstrap\u76f8\u5173\u7684\u6587\u4ef6\u5373\u53ef\u3002<\/span><\/strong><\/p>\n<p>\u56e0\u4e3a\u6211\u9009\u7528\u7684Bootstrap\u6a21\u677f\u662face\uff0c\u8fd9\u91cc\u5c31\u76f4\u63a5\u8bf4\u4e00\u4e0b\u6211\u662f\u5982\u4f55\u5c06ace\u6a21\u677f\u7528\u5728Django\u9879\u76ee\u4e0a\u7684\uff1a<\/p>\n<pre class=\"lang:default decode:true \">#\u5728ui_project\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2a\u53eb\u505aassets\u7684\u76ee\u5f55\u7528\u4e8e\u5b58\u653e\u9759\u6001\u6587\u4ef6\n$ git clone https:\/\/github.com\/bopoda\/ace.git\n$ cp -r ace\/assets\/ .\n$ cp -f ace\/index.html ui_app\/templates\/\n\n$ vim ui_project\/settings.py\n#\u6dfb\u52a0\u4e0b\u9762\u7684\u5185\u5bb9\nPROJECT_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')\nSTATICFILES_DIRS = (\n    os.path.join(BASE_DIR, \"assets\"),\n)<\/pre>\n<p>\u7136\u540e\u53bb\u6d4f\u89c8\u5668\u4e0a\u8bbf\u95ee\uff1a <a href=\"http:\/\/127.0.0.1:8080\/\">http:\/\/127.0.0.1:8080\/<\/a> \u770b\u770b\u6548\u679c\uff0c\u6216\u8005\u901a\u8fc7\u8bbf\u95ee <a href=\"http:\/\/127.0.0.1:8080\/assets\/css\/ace.min.css\">http:\/\/127.0.0.1:8080\/assets\/css\/ace.min.css<\/a>\u00a0\u770bDjango\u662f\u5426\u80fd\u591f\u6b63\u786e\u627e\u5230\u9759\u6001\u6587\u4ef6\u3002<\/p>\n<p>\u4e0a\u9762\u8fd9\u79cd\u4f7f\u7528\u7684\u662fDjango\u81ea\u5e26\u7684Web\u670d\u52a1\u5668\uff0c\u5982\u679c\u9700\u8981\u5728\u7ebf\u4e0a\u8dd1\uff0c\u5efa\u8bae\u4f7f\u7528Nginx+uwsgi\u7684\u65b9\u5f0f\uff0c\u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u4e4b\u524d\u8bb0\u5f55\u7684\u4e00\u7bc7\u6587\u7ae0\u300c<a href=\"http:\/\/ixyzero.com\/blog\/archives\/2722.html\">\u57fa\u4e8eNginx\u548cuwsgi\u5728CentOS\u4e0a\u90e8\u7f72Django<\/a>\u300d\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4f7f\u7528Bootstrap\u6a21\u677f\u7684\u8bdd\uff0c\u53ef\u4ee5\u5728Nginx\u7684\u914d\u7f6e\u6587\u4ef6\u91cc\u9762\u52a0\u4e00\u4e2alocation\uff0c\u8ba9templates\u91cc\u9762\u7684HTML\u4ee3\u7801\u80fd\u591f\u8bbf\u95ee\u5230Bootstrap\u76f8\u5173\u7684CSS\/JS\u6587\u4ef6\u5373\u53ef\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"lang:default decode:true \">server {\n    listen      80;\n    server_name localhost;\n    # ...\n\n    location \/assets {\n        alias \/opt\/learn_django\/ui_project\/assets;\n    }\n\n    #...\n}<\/pre>\n<h5>\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li><a href=\"http:\/\/www.ziqiangxuetang.com\/django\/django-tutorial.html\">Django \u57fa\u7840\u6559\u7a0b<\/a><\/li>\n<li><a href=\"http:\/\/www.tuicool.com\/articles\/RBZ3am\">\u6574\u5408django\u548cbootstrap\u6846\u67b6<\/a><\/li>\n<li><a href=\"http:\/\/www.cnblogs.com\/holbrook\/archive\/2012\/01\/31\/2357354.html\">Django\u5b9e\u6218\uff085\uff09\uff1a\u5f15\u5165bootstrap\uff0c\u8bbe\u7f6e\u9759\u6001\u8d44\u6e90<\/a><\/li>\n<li><a href=\"http:\/\/www.zhihu.com\/question\/29804463\">\u60f3\u7528Django+ Bootstrap\u5199\u4e00\u4e2a\u7f51\u7ad9\uff0c \u6709\u54ea\u4e9b\u6bd4\u8f83\u7cfb\u7edf\u5b8c\u6574\u7684\u4e66\u6216\u8005\u89c6\u9891\u53ef\u4ee5\u53c2\u8003\uff1f<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u8fd9\u662f\u4e00\u4e2a\u770b\u8138\u7684\u793e\u4f1a\uff0c\u5bf9\u4e8e\u5f00\u53d1\u6765\u8bf4\u4e5f\u662f\u8fd9\u6837\uff1a\u5373\u4fbf\u540e\u53f0\u903b\u8f91\u505a\u7684\u5c4c\u70b8\u5929\uff0c\u4f46\u662f\u5982\u679c\u6ca1\u6709\u4e00\u4e2a\u6f02\u4eae [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,7],"tags":[626,627],"class_list":["post-2719","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-programing","tag-bootstrap","tag-django"],"views":7202,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2719"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2719\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}