我有我的网站。它是使用Django制作并部署到Heroku
我使用bootstrap3。在部署到heroku之前,当我在localhost:8000
测试网站时,bootstrap3运行良好
我使用了bootstrap3源文件, NOT 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,我该怎么办?
答案 0 :(得分:0)
虽然它应该双向工作。但我建议使用Bootstrap CDN 。
但如果它不在那里工作,那么只需在生产服务器上运行python manage.py collectstatic
后检查静态文件的存储位置并进行相应的更改。
如果下载的bootstrap现在不起作用,这意味着你的css文件都不会工作,因为你的静态文件存储在python manage.py collectstatic
的其他地方。因此不是下载的bootstrap或cdn的问题。