[英]Django deploy : Should I use bootstrap3 CDN?
我有我的網站。 它使用Django制作並部署到Heroku。
我使用了bootstrap3。 在部署到heroku之前,當我在localhost:8000
測試網站時,bootstrap3可以正常工作。
我使用了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文件都擴展了templates / 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,我該怎么辦?
雖然它應該雙向工作。 但是我建議使用Bootstrap CDN 。
但是,如果它在那里不起作用,那么在生產服務器上運行python manage.py collectstatic
后,請檢查一下靜態文件的存儲位置,並進行相應的更改。
而且,如果下載的引導程序現在不起作用,則意味着您的css文件都無法正常工作,因為您的靜態文件由python manage.py collectstatic
存儲在其他位置。 因此, 這不是下載的引導程序或CDN的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.