繁体   English   中英

Django deploy:我应该使用bootstrap3 CDN吗?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM