金字塔:未找到静态资产

时间:2014-04-22 16:16:09

标签: 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中,我添加了一个静态视图:

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,但是我是否应该为每个静态目录注册单独的静态视图感到困惑,例如。

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')

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

我不是故意回答我自己的问题,而是将/static更改为/static/ /etc/nginx/sites-enabled/default并将所有静态网址设为相关网址。