1

I've downloaded the bootstrap files off the website and created a html document to test bootstrap. I've kept all these files in the template folder of my Django app. Now, bootstrap works when I open the html file directly using my browser, but when I use Django and access it using the server it no longer works. Any idea what the problem may be? I'll provide code to anyone who requests it.

I've now tried these two:

It's still not working unfortunately.

Community
  • 1
  • 1

1 Answers1

4

I've been using bootstrap a lot with my django projects, since I'm a terrible front end, and I had almost the same problem at the very start. The problem is that your templates directory isn't meant to be served by your django application, and it is the client browser who needs the style sheets. Those files which your app needs to work in the client side are called static files and need to be served apart.

You can find everything about managing static files here in a nutshell what you need to do is:

  1. Put you static files in a safe directory, could be PROJECT'S_ROOT/public/static_files.
  2. Add that directory (using a full path) to your STATICFILES_DIRS in settings.py.
  3. Set the STATIC_ROOT and STATIC_URL
  4. Get to serve this files using urls.py

Your choice of using bootstrap is wise :), one can't do everything good. Another recommendation is to use this django-boilerplate that gets out of the box with all of this common little difficult settings, and has a prettier and more production oriented folder structure.

eLRuLL
  • 18,488
  • 9
  • 73
  • 99