简体   繁体   English

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

[英]Django deploy : Should I use bootstrap3 CDN?

I have my website. 我有我的网站。 It is made using Django and deployed to Heroku. 它使用Django制作并部署到Heroku。
And I used bootstrap3. 我使用了bootstrap3。 Before deploying to heroku, when I test website at localhost:8000 , bootstrap3 works well. 在部署到heroku之前,当我在localhost:8000测试网站时,bootstrap3可以正常工作。
I used bootstrap3 source file, NOT CDN . 我使用了bootstrap3源文件, 不是CDN

Below is my source tree. 下面是我的源代码树。

/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

All my html files extends templates/base.html . 我所有的html文件都扩展了templates / base.html
To apply bootstrap3 I coded like this in 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 -->

It is my settings.py to manage staticfiles. 管理静态文件是我的settings.py。

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT=os.path.join(BASE_DIR, 'staticfiles')

After deploying to heroku, I access my website. 部署到heroku后,我可以访问我的网站。 Bootstrap3 is not applied. 没有应用Bootstrap3。 I modified base.html. 我修改了base.html。

I removed href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}" and added CDN . 我删除了href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}"并添加了CDN
bootstrap3 is applied. bootstrap3已应用。

However I want to use bootstrap3 download file. 但是我想使用bootstrap3下载文件。 I don't want to use CDN. 我不想使用CDN。
TO use bootstrap3 in production environment, what should I do? 要在生产环境中使用bootstrap3,我该怎么办?

Though it should work both way. 虽然它应该双向工作。 But I will recommend to use Bootstrap CDN . 但是我建议使用Bootstrap CDN

But if it is not working there, then just have a check where your static files are stored after running python manage.py collectstatic on production server and make changes accordingly. 但是,如果它在那里不起作用,那么在生产服务器上运行python manage.py collectstatic后,请检查一下静态文件的存储位置,并进行相应的更改。

And if downloaded bootstrap is not working now that means none of your css file will work coz your static files are stored somewhere else by python manage.py collectstatic . 而且,如果下载的引导程序现在不起作用,则意味着您的css文件都无法正常工作,因为您的静态文件由python manage.py collectstatic存储在其他位置。 Hence it is not the problem of downloaded bootstrap or cdn. 因此, 这不是下载的引导程序或CDN的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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