简体   繁体   English

金字塔:找不到静态资产

[英]Pyramid: static assets not found

I'm trying to deploy a Pyramid app. 我正在尝试部署Pyramid应用程序。 My domain is wisderm.com . 我的域名是wisderm.com The HTML has loaded, but none of the static assets (css, js, images, fonts) are showing up. HTML已加载,但没有显示任何静态资产(css,js,图像,字体)。

In my /etc/nginx/sites-enabled/default file, I have set the location of the static files as follows, according to this tutorial : 根据本教程 ,在我的/etc/nginx/sites-enabled/default文件中,我将静态文件的位置设置如下:

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: 在我的__init__.py ,添加了一个静态视图:

config.add_static_view('static', 'static', cache_max_age=3600) 

In my HTML templates, I have tried 2 ways of serving static assets: 在我的HTML模板中,我尝试了两种提供静态资产的方法:

<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. 适用于CSS文件和普通的旧的相对URL,例如/static/images/products/product_name/01.jpg其他所有内容。

Neither way works though. 两种方法都行不通。 In the Network tab under Chrome Dev Tools, all of the files have a status code of 404 Not Found . 在Chrome开发者工具下的网络标签中,所有文件的状态码均为404 Not Found

I took a look at the Cookbook page on static files , but it seems to be outdated. 我看了一下静态文件上的Cookbook页面 ,但它似乎已经过时了。 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 /etc/nginx/sites-enabled/default /static/更改为/static/ ,并使所有静态url相对URL对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM