flask url_for 图片URL 缺少端口号
发布日期:2021-05-06 23:49:06 浏览次数:21 分类:技术文章

本文共 387 字,大约阅读时间需要 1 分钟。

参考:

Flask中关于url_for()的坑:

 

需要flask返回服务器上静态文件的url地址:

return url_for('static', _external=True, filename='images/99c5.jpg')

但是在客户端得到的地址为,http://172.168.xx.xx/static/images/99c5.jpg

在浏览器上访问得到的是 404.  缺少端口号(我设置的端口号为86)。

 

解决方法:

在nginx的配置文件 /etc/nginx/conf.d/wsgi.conf 中,将:

proxy_set_header   Host             $host;

更改为:

proxy_set_header   Host             $host:86;

 

此时得到的图片url为:http://172.168.xx.xx:86/static/images/99c5.jpg

 

上一篇:树状数组改段求段
下一篇:flask 404 not found

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年03月09日 22时27分36秒