Reputation: 1570
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.
Upvotes: 3
Views: 3257
Reputation: 103
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.
Upvotes: 1
Reputation: 1046
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">
Upvotes: 3
Reputation: 832
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/'
Upvotes: -2