> I don't think that's the case, and FWIW the OP's layout makes perfect
> sense to me. His point is that even while all apps are in a same
> project and share a common auth, they are otherwise totally (or
> mostly ?) independent so it doesn't really makes sense to put all the
> media together in the project's /static/ dir.
Indeed, that's exactly what i mean.
It just doesn't make sense to put it in the projects static dir.
I found a solution that works for me.
In the application dir, i've made a media\calltracking directory where
the static files go.
I need the extra dirname in the path (the trailing calltracking), otherwise
i end up with media not being found.
This is because of the order media is searched in, as specified in the urls.py
(I'm still developing so the projects hasn't been released yet)
I could work around this by using another media name like calltracking_media
but i don't like that. So the one catch is that i need to place the
application media url's above the project's media url:
urls.py
=======
...
urlpatterns = patterns('',
(r'^%s/(?P<path>.*)$' % settings.CALLTRACKING_MEDIA_URL, 'django.views.static.serve', {'document_root':
settings.CALLTRACKING_MEDIA_ROOT, 'show_indexes': True } ),
(r'^%s/(?P<path>.*)$' % settings.MEDIA_URL, 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True } ),
settings.py
===========
...
MEDIA_URL = '/media'
MEDIA_ROOT = os.path.join(project_path, MEDIA_URL)
MEDIA_ROOT_FILES = "files/"
...
# At the end of the file, import the app specific stuff
from settings_calltracking import *
settings_calltracking.py
========================
...
CALLTRACKING_MEDIA_URL = '/media/calltracking'
CALLTRACKING_MEDIA_ROOT = os.path.join(application_calltracking_path, CALLTRACKING_MEDIA_URL)
CALLTRACKING_MEDIA_FILES = "files/"
...
You still need to expose the new media url to your app.
Since i don't want other applications to be able to access other apps settings,
i chose to work with a custom template tag instead of working with the request context.
templatetags\media.py in the app dir
...
def do_expose_app_media(parser, token):
return template.TextNode(settings.CALLTRACKING_MEDIA_URL)
register.tag('media_url', do_expose_app_media)
I could use simpletag too.
In my calltracking templates i can now access the app media via {% media_url %}
{% load media %}
<link rel="stylesheet" type="text/css" href="{% media_url %}/style/list.css" />
It seems like a fairly clean solution except for the order i have to put the media
url's in, but i don't mind.
> FWIW, even for a more canonical "integrated" website / webapp composed
> of distinct django apps, "assets" (app specific css, js, images and
> whatnot) management can sometimes be a pain. My own solution so far is
> to keep all app-specific static stuff in a /medias/<appname> subir of
> the app and manually symlink this to the project's /static dir, but
> I'd really enjoy a better solution.
I'm developing on Windows so i don't have the luxury of a nicely working
symlink system :)
I like your solution too as you only have a symlink in the media directory
and the static data actually is placed in the application directory.
Regards,
Benedict
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment