python - Pyramid :找不到静态 Assets

标签 python nginx pyramid

我正在尝试部署 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/

相关文章:

python - '@reify' 有什么作用,什么时候应该使用它?

python - 快速查找最近更改的文件

node.js - Socket.io 无法在 Node.js 前面使用 Nginx 反向代理

node.js - 生产环境中的 Socket.io 和 nginx CORS

python - Pyramid :Ngi​​nx + Pserve 还是 Nginx + wsgi?

python - 如何访问 ${buildout :directory} from Python code?

python - 将.txt数据保存在Excel工作表中

python - 如何显示不带引号且以逗号作为分隔符的 NumPy 字符串数组?

Python变量怪异?

node.js - 为什么容器 IP 和别名之间的交换会导致 AJAX 请求出现差异?