Domanda

In a pyramid application, I defined a static view for serving css/js files and another one to serve others datas like uploaded files:

config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('uploads', path='/data/uploads')

On the template side, i'm using request.static_url() to access to static files:

<script type="text/javascript" src="${request.static_url('myapp:static/js/jquery-1.8.3.min.js')}"></script>

The problem is I don't know how to use request.static_url() with the second definition (uploads), what i did never works and crash the app:

${request.static_url('uploads/a_named_file')}

Can you just explain me how to do please? Thanks by advance.

È stato utile?

Soluzione

Looks like you forgot to include the full path:

${request.static_url('/data/uploads/a_named_file')}

Static assets are looked up based on the matching path you registered for the static assets. For your two static view registrations, you use the paths static and /data/uploads, respectively. The first one is relative to myapp, but the second one is an absolute path. When using an absolute path for a static view, you need to use the same absolute path when generating static URLs.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top