Lorenzo
Lorenzo

Reputation: 4648

Serving static files in Django development

I have a problem serving static files in development using Django 1.4

STATIC_ROOT = 'C:/projects/foobar/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = ()

In my templates I refer to this as static like this:

<link rel='stylesheet' href='/static/foobar.css'>

Notice that I'm not using any context processor as I'm hard-coding static

Based on the docs I can't see what I'm doing wrong

Upvotes: 0

Views: 236

Answers (1)

Lorenzo
Lorenzo

Reputation: 4648

Ok I've found a solution:

STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ('C:/projects/foobar/static',)

This way I just refer to /static/ from within the templates. It's weird that STATIC_ROOT needs to be emtpy and STATICFILES_DIRS is what counts though, it's counter-intuitive.

This doesn't require for the static folder to be inside an app, it can just be in the project's root and it requires no change to urls.py nor the use of the collectstatic command

Upvotes: 1

Related Questions