Hello,

On 08/15/2014 05:39:51 PM, davide moro wrote:

> I've registered a static view
> 
>     >>> config.add_static_view('images',
> 'p_started:webapp/app/images', 
> cache_max_age=3601)


> So depending on
> the 
> .ini settings my app will register webapp/app/images or
> webapp/dist/images 
> (to be used in production, with image optimized)

> The only problem I that request.static_url uses the path and not the
> name 
> registered in add_static_view, causing a value error.
> 
> Is there a way to generate a static url using the name "images"
> registered 
> in add_static_view?
> I mean:
>     >>> ${request.static_url('p_started:images/pyramid.png')}
> instead of:
>     >>> ${request.static_url('p_started:webapp/app/images/
> pyramid.png')}
> I want to use the name because the path will change depending on the 
> deployment settings. 

I don't know how to do what you want, and am not particularly
experienced with pyramid.  But if the path changes based
on deployment settings why not use the deployment settings
value everywhere and make that relationship explicit?

In the .ini:

minify=app

Then in the code:

  config.add_static_view('images',
                         , 'p_started:webapp/'
                           + config.registry.settings['minifiy']
                           + '/images' 
                         , cache_max_age=3601)


And:


  ${request.static_url('p_started:images/'
                           + request.registry.settings['minifiy']
                           + '/images')

There's probably a better way to abstract this, but you get the
idea.

See:

http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/
startup.html#deployment-settings


http://docs.pylonsproject.org/projects/pyramid/en/latest/api/
registry.html#pyramid.registry.Registry.settings

Regards,

Karl <k...@meme.com>
Free Software:  "You don't pay back, you pay forward."
                 -- Robert A. Heinlein

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-devel+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to