简体   繁体   中英

Django deploy : Should I use bootstrap3 CDN?

I have my website. It is made using Django and deployed to Heroku.
And I used bootstrap3. Before deploying to heroku, when I test website at localhost:8000 , bootstrap3 works well.
I used bootstrap3 source file, NOT 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 .
To apply bootstrap3 I coded like this in 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.

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. Bootstrap3 is not applied. I modified base.html.

I removed href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}" and added CDN .
bootstrap3 is applied.

However I want to use bootstrap3 download file. I don't want to use CDN.
TO use bootstrap3 in production environment, what should I do?

Though it should work both way. But I will recommend to use 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.

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 . Hence it is not the problem of downloaded bootstrap or cdn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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