This is the purpose of the AssetResolver. resolver = AssetResolver() asset = resolver.resolve('mypkg:static/img/%s' % img_filename) asset.abspath() # -> /foo/bar/static/img/...
http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/api/path.html#pyramid.path.AssetResolver On Wed, May 1, 2013 at 11:41 AM, Laurent DAVERIO <ldave...@gmail.com> wrote: > Hello list, > > sorry for asking such a newbie question (and making you work on May Day > ;-), but I can't seem to find the answer by myself... :-( > > > I have a Pyramid app defining a few static routes, e.g. : > > > for d in ('css', 'img', 'js'): > > config.add_static_view('%s' % d, 'mypkg:static/%s' % d, > cache_max_age=3600) > > This allows me to use static assets in my templates, e.g.: > > > <img src="${request.static_url('mypkg:static/img/%s' % img_filename}" /> > > > Now, I would like to test in my view if "img_filename" corresponds to an > existing file. > > Is there an easy way to get the physical file path from the asset > specification ? Of course, I don't want to hardcode the image directory > path in my code, and I'd also like to avoid having to add a new setting > ("image_dir=...") to my development.ini. > > Many thanks in advance, > > > Laurent. > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pylons-discuss+unsubscr...@googlegroups.com. > To post to this group, send email to pylons-discuss@googlegroups.com. > Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.