Hello

Django has a really useful API for associated media files with Forms,
Widgets, etc.
http://docs.djangoproject.com/en/dev/topics/forms/media/#paths-in-media-definitions

This is very good when dealing with just one app.

However, many apps I write are a collection of multiple apps. These
apps may be written by multiple people.


This raises some issues:

* If you are writing an app that is designed to be reusable, and comes
with say a JavaScript file, what path should you use to reference the
file? Different people seem to have different directory structures for
media files, and the code is hardly reusable if you have to customize
it for each project.

You could make every media file a configurable setting, if you have
lots of settings that starts getting messy. Or maybe you could have
every app use its own x_MEDIA_URL settings.


* How do you serve media files from multiple apps?

The solution to this last point I have seen so far is that the media
files should be included in under the same app that has ROOT_URLCONF.
This fits in with sample Django code I often see:

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^something_media/(?P<path>.*)$',
'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
    )

However this can be messy as the media files may be closely tied to
the html templates in another app. I don't think it is a good idea to
artificially split files into different apps like this.

Another idea I have had is to write a script that combines files from
$dir/media for every app into one global media directory, and
configure apache or django to serve files from this directory. That
way you get to keep small URLs, and can have one app override the
media files. In fact you could replace the "copy" operation with
something that compresses Javascript/css code making download times
faster.


I can't help but think that requiring every project come up with their
own solution is bad for code re-usability. As much as I like D


Comments? Suggestions?

Thanks!


Brian May

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to