问题:python的os.path如何使用
解决:亲自测试
方法:
代码如下:
img = "/static/uploads/social/tmp/aa.png"
imgP = os.path.realpath(os.path.join(os.path.dirname(__file__), '..') + img)
一、os.path.dirname(__file__) 当前运行文件的路径,获得 /var/www/hello/website/server
二、os.path.join(os.path.dirname(__file__), '..') 连接两个路径,获得 /var/www/hello/website/server/..
三、 imgP 获得连接后的路径,获得 /var/www/hello/website/static/uploads/social/tmp/aa.png