Reputation: 3420
I am trying to integrate Twitter bootstrap with my django application. In settings.py, I have:
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
"/path/to/my/projects/templates/static/",
)
Under the static
folder, there are 3 folders namely, css, img and js and all the bootstrap files have been copied into it as is.
My template looks like so:
<html>
<head>
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap-responsive.css' %}" />
<script type="text/javascript" src="{% static 'js/bootstrap.js' %}"></script>
<meta charset="utf-8">
<title>Test App</title>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active">
<a class="brand" href="#">TEST APP</a>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
How ever, when I run the development server, I get a basic html page with no change and no css applied.
What am I doing wrong here?
Upvotes: 3
Views: 672
Reputation: 82470
Assuming that your static
folder is immediately underneath your Application root, this is a method that you could use to bullet-proof static file template rendering on all OSs.
import os
def replace(path):
assert isinstance(path, str)
return path.replace('\\', os.sep)
def here(*args):
return replace(os.path.abspath(os.path.join(os.path.dirname(__file__), *args)))
BASE_DIR = here('..')
def root(*args):
return replace(os.path.abspath(os.path.join(BASE_DIR, *args)))
STATICFILES_DIRS = (root('static'),)
Upvotes: 2