2017-09-09 26 views
1

我有我的網站。它使用Django製作並部署到Heroku。
而我用bootstrap3。在部署到heroku之前,當我測試網站localhost:8000時,bootstrap3運行良好。
我用bootstrap3源文件,不是CDNDjango部署:我應該使用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,我該怎麼辦?

+0

*「我不想使用CDN」* - 爲什麼不呢? – jonrsharpe

回答

0

雖然它應該雙向工作。但我會推薦使用Bootstrap CDN

但是,如果它不在那裏工作,那麼只需在生產服務器上運行python manage.py collectstatic後檢查靜態文件的存儲位置,並相應地進行更改。

如果下載的引導程序現在不工作,這意味着您的css文件都不會工作,因此您的靜態文件將存儲在其他地方python manage.py collectstatic。因此它不是下載引導程序或cdn的問題。