我正在尝试部署 Pyramid 应用程序。我的域名是wisderm.com 。 HTML 已加载,但没有显示任何静态资源(css、js、图像、字体)。
在我的 /etc/nginx/sites-enabled/default
文件中,我已根据 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;
}
在我的__init__.py
中,我添加了一个静态 View :
config.add_static_view('static', 'static', cache_max_age=3600)
在我的 HTML 模板中,我尝试了两种提供静态资源的方法:
<link href="{{request.static_url('skinproject:static/css/<mycssfile>)}}">
对于 CSS 文件和普通的旧相对 URL,例如 /static/images/products/product_name/01.jpg
对于其他所有内容。
但这两种方法都行不通。在 Chrome 开发工具下的“网络”选项卡中,所有文件的状态代码均为 404 Not Found
。
我看了一下Cookbook page on static files ,但似乎已经过时了。我还检查了official documentation about static assets ,但对于是否应该为每个静态目录注册单独的静态 View 感到困惑,例如
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')
这样做的正确方法是什么?
最佳答案
我并不是要回答我自己的问题,而是将 /etc/nginx/sites-enabled/default 中的
并使所有静态网址相对网址对我有用。/static
更改为 /static/
关于python - Pyramid :找不到静态 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23224887/