Confused by STATICFILES_DIRS not working

5,388 views
Skip to first unread message

Jeff Blaine

unread,
Dec 16, 2011, 11:08:26 AM12/16/11
to django...@googlegroups.com
I'm having a heck of a time getting STATICFILES_DIRS working.  If anyone could shed some light on this or just point me to the "All of your Django STATIC* Settings Clarified Completely Once and For All" blog post or somesuch, I would really appreciate it.

STATIC_ROOT = '' # DEFAULT
STATIC_URL = '/static/' # DEFAULT
STATICFILES_DIRS = ( 
    '/django_sites/new_rcfhostdb/static',
)

Proof the intended CSS file exists in STATICFILES_DIRS:

-rw-r--r-- 1 jblaine wheel 56360 Dec 14 19:06 /django_sites/new_rcfhostdb/static/bootstrap.css

I issue a GET /hostdb/

"ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting"

Fine.

STATIC_ROOT = '/tmp/SHUT_UP'

That stops the 'ImproperlyConfigured' exception.

The various attempted stylesheet references (from my base.html template) and their 404 errors:

<link rel="stylesheet" href="/bootstrap.css" />

[16/Dec/2011 10:53:04] "GET /bootstrap.css HTTP/1.1" 404 2146

<link rel="stylesheet" href="bootstrap.css" />

[16/Dec/2011 10:53:08] "GET /hostdb/bootstrap.css HTTP/1.1" 404 2146

<link rel="stylesheet" href="/static/bootstrap.css" />

[16/Dec/2011 10:57:13] "GET /static/bootstrap.css HTTP/1.1" 404 1741

Tom Evans

unread,
Dec 16, 2011, 11:17:32 AM12/16/11
to django...@googlegroups.com

1) Is staticfiles in INSTALLED_APPS ?
2) Is DEBUG=True?
3) What is the output of:
python manage.py findstatic bootstrap.css

Cheers

Tom

Tom Evans

unread,
Dec 16, 2011, 11:18:09 AM12/16/11
to django...@googlegroups.com
On Fri, Dec 16, 2011 at 4:17 PM, Tom Evans <teva...@googlemail.com> wrote:
>
> 1) Is staticfiles in INSTALLED_APPS ?
> 2) Is DEBUG=True?
> 3) What is the output of:
>  python manage.py findstatic bootstrap.css
>
> Cheers
>
> Tom

Sorry, and:

4) Are you using runserver?

Cheers

Tom

Ivo Brodien

unread,
Dec 16, 2011, 11:25:17 AM12/16/11
to django...@googlegroups.com
Hi,

I am not trying to understand what you did but just tell you how t works for me:

PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_PATH, 'static')
STATIC_URL = '/static/‘

INSTALLED_APPS = (
...

    'django.contrib.staticfiles’,
)

I have no STATICFILES_DIRS defined since for me it is enough how  STATICFILES_FINDERS finds static content.

I think what you get wrong, is that you want to add your folder where you want your static content to be collected to  STATICFILES_DIRS, but that must be defined in STATIC_ROOT and should not be left empty.

When you do runserver it will find and serve all static content automatically

for example static content that is in one of your apps:

django_sites/new_rcfhostdb/MYAPP/static (you DONT have to put this in STATICFILES_DIRS)

When you then run the collectstatic (usually on the production server) command all static content will be copied to STATIC_ROOT and I guess you want this to be: 

django_sites/new_rcfhostdb/static

You have to copy all the static content to one location because only then the Webserver can find and serve all the static content which should not be the job of the django process.


Please read for further information:


Good luck
Ivo





--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/cSCoskQNgFYJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Jeff Blaine

unread,
Dec 16, 2011, 2:17:15 PM12/16/11
to django...@googlegroups.com
On Friday, December 16, 2011 11:18:09 AM UTC-5, Tom Evans wrote:
On Fri, Dec 16, 2011 at 4:17 PM, Tom Evans <teva...@googlemail.com> wrote:
>
> 1) Is staticfiles in INSTALLED_APPS ?

Yes, django.contrib.staticfiles is in INSTALLED_APPS
 
> 2) Is DEBUG=True?

Yes
 
> 3) What is the output of:
>  python manage.py findstatic bootstrap.css

 No matching file

4) Are you using runserver?

Yes
 

Thabang Bernette Tseboho

unread,
Sep 23, 2014, 4:41:13 AM9/23/14
to django...@googlegroups.com, i...@brodien.de
Hi Ivo,

I have my project set up exactly as you suggested, and everything works in production. But I run into 2 problems.

1. When DEBUG=True, all my frontend styling is knocked out. So I resort to;
   
    STATIC_URL = '/static/'
    if DEBUG:
        STATIC_URL = 'static/'

2. which then leaves the backend styling and static knocked out.

Any experience with this?

Collin Anderson

unread,
Sep 23, 2014, 8:49:52 AM9/23/14
to django...@googlegroups.com, i...@brodien.de
How are you referencing your css and images in the frontend?

It should be something like
<img src="{% static "my_app/myexample.jpg" %}" alt="My image"/>



Thabang Bernette Tseboho

unread,
Sep 23, 2014, 9:20:43 AM9/23/14
to django...@googlegroups.com, i...@brodien.de
Yes, that is how my urls are built. This works perfectly till I have DEBUG=TRUE.

Collin Anderson

unread,
Sep 23, 2014, 2:46:03 PM9/23/14
to django...@googlegroups.com, i...@brodien.de
So it works fine in production, when DEBUG = False, but not on your local runserver when DEBUG = True?

Thabang Bernette Tseboho

unread,
Sep 24, 2014, 3:08:40 AM9/24/14
to django...@googlegroups.com

Yes, it's very odd. The only thing that fixes it is setting STATIC_URL="static/" instead if "/static/"

On 23 Sep 2014 8:47 PM, "Collin Anderson" <cmawe...@gmail.com> wrote:
So it works fine in production, when DEBUG = False, but not on your local runserver when DEBUG = True?

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/MUwh10d2Ow8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages