Reputation: 2149
I've added in settings.py
following:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '/static/')
in urls.py
:
urlpatterns = patterns('^/static/$',
# ... the rest of your URLconf goes here ...
url(r'^$', home, name='home'),
url(r'^admin/', include(admin.site.urls))
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
in models.py
:
class Search(models.Model):
question = models.URLField()
query = models.CharField(max_length=255)
in views.py
:
def home(request):
print ' base dir %s' % BASE_DIR
print ' static dir %s' % STATIC_URL
form = SearchForm()
return render_to_response('base.html', {'form': form},
context_instance=RequestContext(request))
and templates/base.html
:
{% load staticfiles %}
<head>
<link href="{{ STATIC_URL }}bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<script src="{{ STATIC_URL }}bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<title>Walker</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="form-group">
<form name="query">
{{ form.as_p }}
</form>
</div>
</div>
</div>
</div>
</body>
I ran ./manage.py collectstatic
with no porblems, folder static
being created.
When I execute ./manage.py runserver
I can see in terminal this error:
base dir home/my/code/walker
static dir /static/
"GET /static/bootstrap/js/bootstrap.min.js HTTP/1.1" 404 1691
Template loading correctly. But bootstrap do not
Several hour can noot figure out what I need to do
Upvotes: 0
Views: 1979
Reputation: 664
If you store static files in locations other than app/static
I think you need to specify STATICFILES_DIRS
in your settings.py
otherwise they will not be collected:
STATICFILES_DIRS = (
"/path/to/static", #collectstatic will find any app/static directories so do not add those here
)
By default it is empty.
Additionally, specify static files using href="{% static 'my-static.css' %}"
instead of {{ STATIC_URL }}
You can also use findstatic to check if your static files are able to be located by the server.
Upvotes: 2