Tuesday, September 23, 2014

Re: Confused by STATICFILES_DIRS not working

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?

On Friday, 16 December 2011 18:25:17 UTC+2, Ivo Brodien wrote:
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





On Dec 16, 2011, at 17:08 , Jeff Blaine wrote:

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

--
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.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bd4b3a8c-afbd-4e7c-a5d0-810b37d53d8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment