简体   繁体   中英

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 /etc/nginx/sites-enabled/default /static/更改为/static/ ,并使所有静态url相对URL对我有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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