3

I have a webpage in Django and now I want to add some CSS (twitter bootstrap) to it. This is the first I am trying. I have carefully read the docs and did everything said there for the django development server to work. I am using development server with debug=True and django version 1.6.5. My settings.py looks like this:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
 )

My files are under /mysite/static/bootstrap/css folder and in my template.html I have this:

{% load staticfiles %}
<link href="{% static "boostrap/css/bootstrap.css" %}" rel="stylesheet" media="screen">

Unfortunately, nothing happens, I see that the development server says:

 "GET /static/boostrap/css/bootstrap.css HTTP/1.1" 500 59

which means it cannot find them. I even tried doing the settings without STATIC_ROOT, doing this:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
    '/static/',
)

but then the development server returns:

"GET /static/boostrap/css/bootstrap.css HTTP/1.1" 404 1682

Any help appreciated.

darxsys
  • 1,560
  • 4
  • 20
  • 34
  • Did you add a path to your `urls.py` for those static files to be found (something like this: http://stackoverflow.com/questions/2237418/serving-static-media-during-django-development-why-not-media-root)? – erewok May 22 '14 at 22:11
  • No, docs says nothing about this. – darxsys May 22 '14 at 22:14
  • Huh, I've been doing it like this for awhile now (didn't realize it was supposed to serve this view automagically; now I'm wondering what I'm doing wrong): https://docs.djangoproject.com/en/1.6/ref/contrib/staticfiles/#django.contrib.staticfiles.views.serve – erewok May 22 '14 at 22:16

3 Answers3

3

You did everything right, the issue here is a simple typo.

Your static files are located in bootstrap

But, in your html, your wrote: {% static "boostrap/css/bootstrap.css" %}

There is a T missing.

The code below will work:

{% load staticfiles %}
<link href="{% static "bootstrap/css/bootstrap.css" %}" rel="stylesheet" media="screen">
vincedjango
  • 1,022
  • 1
  • 13
  • 24
1

You have to load the STATIC file into your project app folder.

---> If your project Name is myblog. You will find another folder named myblog into myblog and you have to place your static folder there.

---> In setting.py you have to add:

  STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'myblog/static'), )

In your production mode if you collect static , static file will be copied in root static.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
-2

I find this problem many times and every time problem was solved by add url into STATIC_URL i.e.

STATIC_URL = 'http://localhost:8000/static/'
Alexey
  • 812
  • 13
  • 22