NEW Feature: Collect static order of directories searched. Possible upgrade inside FileSystemFinder.

66 views
Skip to first unread message

Radosław Orłowski

unread,
Mar 10, 2017, 7:35:25 AM3/10/17
to Django developers (Contributions to Django itself)
Right now I'm working with Django 1.8.17 and What I'm trying to acomplish is simple override of static files.

STATICFILES_DIRS = (
        str(os.path.abspath(os.path.join(SITE_ROOT, 'static_new'))),
        str(os.path.abspath(os.path.join(SITE_ROOT, 'static'))),
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

my thinking:
I have to sites that need different logo file.

Both directories static and static_new have images/logo.png, but this file is different.

I need to add logo from static_new and load rest of content from static (js, css. etc)
This would allow me to create folders with statics -- per site without changing urls and templates, just collect static would take images from another dir, other changes are made with  django.contrib.sites.models.get_current_site
Collect static works with first found but I have no way to define 'seach here first behavior'. Also development static and collectstatic don't seem to search for those files with same order (also I find them both unstable as once in a while logo is loaded from static_new and mostly from static)


Expected behavior:
when adding new folder to STATICFILES_FINDERS, I can somehow define order of folders static file finder will go through searching for this item either as alphabetic order or by explicit order. ('static',2),('static_new',1)
second behavior is similar to list_display and fieldsets in admin views, I would love to introduce here something like that.


Discussion open.

Tim Graham

unread,
Mar 10, 2017, 8:35:20 AM3/10/17
to Django developers (Contributions to Django itself)
Hi, I'm surprised if the search behavior is nondeterministic rather than searching STATICFILES_DIRS in order. If that's really the case, it seems like a bug. Can you point to the code that causes the nondeterminism?

René Fleschenberg

unread,
Mar 10, 2017, 1:05:12 PM3/10/17
to django-d...@googlegroups.com
Hi Radosław,

On 03/10/2017 11:49 AM, Radosław Orłowski wrote:
> Right now I'm working with Django 1.8.17 and What I'm trying to
> acomplish is simple override of static files.
>
> STATICFILES_DIRS = (
> str(os.path.abspath(os.path.join(SITE_ROOT, 'static_new'))),
> str(os.path.abspath(os.path.join(SITE_ROOT, 'static'))),
> )
>
> STATICFILES_FINDERS = (
> 'django.contrib.staticfiles.finders.FileSystemFinder',
> 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
> )
>
> my thinking:
> I have to sites that need different logo file.
>
> Both directories static and static_new have images/logo.png, but this
> file is different.
>
> I need to add logo from static_new and load rest of content from static
> (js, css. etc)


You mentioned that you have two sites. Are you using the sites
framework? Then you should have a separate settings module for each
site, so you can just give them different settings:


```
# settings_site1.py
# site1 only uses files from ``static``.
SITE_ID = 1
STATIC_ROOT = '/var/static/site1'
STATICFILES_DIRS = (
os.path.abspath(os.path.join(SITE_ROOT, 'static')),
)


# settings_site2.py
# site2 uses files from ``static_new``, and falls back to ``static``
SITE_ID = 2
STATIC_ROOT = '/var/static/site2'
STATICFILES_DIRS = (
os.path.abspath(os.path.join(SITE_ROOT, 'static_new')),
os.path.abspath(os.path.join(SITE_ROOT, 'static')),
)



Regards,
René

--
René Fleschenberg

Luke Plant

unread,
Mar 11, 2017, 4:49:43 AM3/11/17
to django-d...@googlegroups.com

Like Tim, I'm surprised if there is non-determinism in the order here - a quick look at the code shows the search is in the order specified in  STATICFILES_DIRS. Is it possible you are encountering browser caching effects, perhaps triggered by accessing both sites on 'localhost' locally?


Luke
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/86d68df8-38e0-4dad-ab93-6d12e1d2eeba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages