我有我的網站。它使用Django製作並部署到Heroku。
而我用bootstrap3。在部署到heroku之前,當我測試網站localhost:8000
時,bootstrap3運行良好。
我用bootstrap3源文件,不是CDN。Django部署:我應該使用bootstrap3 CDN嗎?
下面是我的源代碼樹。
/home/<path>/multichat$ tree
.
├── manage.py
├── static
│ ├── bootstrap-3.3.7-dist
│ │ ├── css
│ │ │ ├── bootstrap-theme.css
│ │ │ ├── bootstrap-theme.css.map
│ │ │ ├── bootstrap-theme.min.css
│ │ │ ├── bootstrap-theme.min.css.map
│ │ │ ├── bootstrap.css
│ │ │ ├── bootstrap.css.map
│ │ │ ├── bootstrap.min.css
│ │ │ └── bootstrap.min.css.map
│ │ ├── fonts
│ │ │ ├── glyphicons-halflings-regular.eot
│ │ │ ├── glyphicons-halflings-regular.svg
│ │ │ ├── glyphicons-halflings-regular.ttf
│ │ │ ├── glyphicons-halflings-regular.woff
│ │ │ └── glyphicons-halflings-regular.woff2
│ │ └── js
│ │ ├── bootstrap.js
│ │ ├── bootstrap.min.js
│ │ └── npm.js
│ ├── css
│ │ └── base.css
│ └── js
│ └── jquery-1.12.2.min.js
├── staticfiles
│ └── default_profile.png
└── templates
├── 404.html
├── 500.html
├── base.html
├── home.html
└── index.html
我所有的HTML文件,從而擴展模板/ base.html文件。
要應用bootstrap3我編碼像這樣在base.html。
<!-- bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}" type="text/css" />
<!-- Optional theme -->
<link rel="stylesheet" href="{% static 'bootstrap-3.3.7-dist/css/bootstrap-theme.min.css' %}" type="text/css" />
<!-- Latest compiled and minified JavaScript -->
<script src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.min.js' %}" type="text/javascript"></script>
<!-- bootstrap end -->
這是我的settings.py管理靜態文件。
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT=os.path.join(BASE_DIR, 'staticfiles')
部署到heroku後,我訪問我的網站。 Bootstrap3未應用。我修改了base.html。
我刪除href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}"
並添加了CDN。
bootstrap3被應用。
但是我想使用bootstrap3下載文件。我不想使用CDN。
要在生產環境中使用bootstrap3,我該怎麼辦?
*「我不想使用CDN」* - 爲什麼不呢? – jonrsharpe