Question

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, e.g.

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?

Was it helpful?

Solution

I didn't mean to answer my own question, but changing /static to /static/ in /etc/nginx/sites-enabled/default and making all static urls relative urls worked for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top