Django: how to make STATIC_URL empty?

后端 未结 2 656
醉话见心
醉话见心 2021-01-24 06:56

Yep, I want it to work like in Flask framework - there I could set parameters like this:

static_folder=os.getcwd()+\"/static/\", static_url_path=\"\"

<
2条回答
  •  清歌不尽
    2021-01-24 07:38

    This is really easy to accomplish with Nginx using try_files. Using the pseudo-settings below will make Nginx try to find a static file first, and if it fails then execution is passed to your django app.

    server {
      ...
      root /some/path/to/assets/;
      try_files $uri @django;
    
      location @django {
        ...
        proxy_pass  http://unix:/some/path/to/server.sock;
      }
    }
    

    Example: The file /some/path/to/assets/myfile.ext will be available as http://mydomain/myfile.ext

提交回复
热议问题