Well I'm trying to use Bootstrap with Django by copying and pasting the folders from Bootstrap to static folder. But I'm not able to get access to the Bootstrap.css file. It shows 404 error.
Just for experimenting purpose, I created a main.css in the static/css folder and linked it in the template and to my surprise, its running.
So, why the bootstrap.css file is not getting linked.
Here is how I'm linking Bootstrap.css in my template
{% block css %}
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.css">
{% endblock %}
Here is my root urls.py
urlpatterns = patterns('',
(r'^',include('apps.home.urls')),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':os.path.normpath( os.path.join( os.path.dirname(__file__),'../static/'))}),
url(r'^admin/', include(admin.site.urls)),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
MEDIA_ROOT = 'C:/Users/Praful/uploads'
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
You should try this instead:
{% load static %}
{% block css %}
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.css ' %}">
{% endblock %}
...and just make sure you have 'django.contrib.staticfiles' in your INSTALLED_APPS. Please see also https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#template-tags
(EDIT: fixed typo, I oroginally forgot the "static" keyword)
OR this:
{% block css %}
<link rel="stylesheet" type="text/css" href="{{STATIC_URL}}css/bootstrap.css">
{% endblock %}
..assuming "django.core.context_processors.media" is in your TEMPLATE_CONTEXT_PROCESSORS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With