On 1 oct, 10:55, Benedict Verheyen <benedict.verhe...@gmail.com> wrote:
> 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. FWIW, this mirrors the usual pattern for app templates / project templates. > 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) > > 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 } ), > This is fine when using the dev server, but what when you will serve your static files directly from the frontend web server ? > 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/" > ... Same question here - how will this save you the pain from having to either symlink (or alias in your apache conf) each and any app's media folder when deploying to the production server ? > 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 %} Hmmm... And how will it work when you'll add a second, then a third app with to your project ? I didn't checked for some times now but AFAICT we still don't have namespaced template tags / filters. <thinking-out-loud> Since you went the templatetag route, you could extract your templatetag into a distinct app and rewrite it to accept the appname as param so it would work with as many apps as you want. </thinking-out-loud> > > 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 :) ??? Windows is STILL not able to properly handle symlinks ??? OMG :( > 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. I think it's more or less a canonical solution but it's far from ideal. Now I never spent any time thinking of a better one :-/ -- 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.