简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM