0

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

Lorenzo
  • 4,558
  • 11
  • 44
  • 54
  • 1
    http://stackoverflow.com/questions/10460028/confusion-in-django-admin-static-and-media-files/10460116#10460116 – Hedde van der Heide May 29 '12 at 20:37
  • ArgsKwards not helpful as I already pointed out the docs and I'm not using collect static because Django docs say I don't have to in dev, I can just run the devserver and static files will be served from my specified STATIC_ROOT and STATIC_URL – Lorenzo May 29 '12 at 20:42
  • Have you added the relevant lines to your main urls.py? – Tom May 29 '12 at 20:44
  • You'll still need to follow the part of the answer where they add the static files urls to the url conf. Django won't magically serve those files if you aren't using the context processor. – Jack Slingerland May 29 '12 at 20:44
  • Read a bit further than line 1... – Hedde van der Heide May 29 '12 at 20:50
  • Tom, Jack, there's no need to add the static file urlpatterns if I'm using runserver. This is what the docs say (link in my question). But it doesn't seem to work. From the docs: "This view is automatically enabled and will serve your static files at STATIC_URL when you use the built-in runserver management command. To enable this view if you are using some other server for local development, you'll add a couple of lines to your URLconf." – Lorenzo May 29 '12 at 20:59

1 Answers1

1

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

Lorenzo
  • 4,558
  • 11
  • 44
  • 54