I recently came across a problem when using ManifestStaticFilesStorage on 
an app with form media, which the documentation doesn't seem to address. 
I'm posting here rather that on django-users, since I think we ought to at 
least document how to fix it, or preferably come up with a better way of 
solving it.

The app I was using is django-image-cropping, which specifies the media for 
a widget like this (see image_cropping/widgets.py#L60 
<https://github.com/jonasundderwolf/django-image-cropping/blob/5005764036fe680a98bf168a764108a67b3830bc/image_cropping/widgets.py#L60>
):

    def _media(self):
        js = [
            "image_cropping/js/jquery.Jcrop.min.js",
            "image_cropping/image_cropping.js",
        ]

        css = {'all': ("image_cropping/css/jquery.Jcrop.min.css",
                       "image_cropping/css/image_cropping.css",)}
        return forms.Media(css=css, js=js)

    media = property(_media)

When rendered to HTML, it generates a static path (i.e. STATIC_URL is 
prepended), but doesn't correctly generate paths to minified content, so 
you get 404s. django.contrib.admin has worked around this - by using the 
admin_static template tag (see 
django/contrib/admin/templatetags/admin_static.py#L10 
<https://github.com/django/django/blob/037f81fedcbe860bacea01fa6415849e0e379c15/django/contrib/admin/templatetags/admin_static.py#L10>).
 
I fixed up django-image-cropping by porting that workaround to the app 
itself (see PR 
<https://github.com/jonasundderwolf/django-image-cropping/pull/71>), but it 
feels like it might be worth documenting how people should be handling this 
in their apps. I'm thinking of something along the lines of making the code 
in admin_static.py less admin specific (so far as I can see, it doesn't 
actually have anything to do with django.contrib.admin) - perhaps exposing 
the functionality in django.utils, and then having the templatetag 
admin_static use that function.

If I've missed something, my apologies, but I couldn't find any tickets 
related to this. It seems like something others would have come across 
already, so again, apologies if there's already a ticket for this, or if 
I've gone about this in a braindead way.

If patches/tickets need writing, I'd be happy to get stuck in - just wanted 
some clarity that I'm not crazy first :)

Dom

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/4683fd0f-9580-4d65-b303-b4a6667bdf37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to