Pyramid: static assets not found
I'm trying to deploy a Pyramid app. My domain is wisderm.com. The HTML has loaded, but none of the static assets (css, js, images, fonts) are showing up.
In my /etc/nginx/sites-enabled/default
file, I have set the location of the static files as follows, according to this tutorial:
location /static {
root /home/SkinProject;
# this path + /skinproject/static is the absolute
# path to my static directory
expires 30d;
add_header Cache-Control public;
access_log off;
}
In my __init__.py
, I have added a static view:
config.add_static_view('static', 'static', cache_max_age=3600)
In my HTML templates, I have tried 2 ways of serving static assets:
<link href="{{request.static_url('skinproject:static/css/<mycssfile>)}}">
for CSS files and plain old relative URLs like /static/images/products/product_name/01.jpg
for everything else.
Neither way works though. In the Network tab under Chrome Dev Tools, all of the files have a status code of 404 Not Found
.
I took a look at the Cookbook page on static files, but it seems to be outdated. I also checked the official documentation about static assets, but am confused as to whether I should register separate static views for each static directory, eg
config.add_static_view(name='http://wisderm.com/images', path='skinproject:static/images')
config.add_static_view(name='http://wisderm.com/css', path='skinproject:static/css')
What is the right way of doing this?
我不是故意回答我自己的问题,而是将/static
改为/static/
in /etc/nginx/sites-enabled/default
并让所有静态url相对于urls为我工作。
上一篇: 如何从Java请求不同的会话ID
下一篇: 金字塔:找不到静态资产