我的Django应用程序通过Apache创建日志文件:log.txt
此文件的所有者和组是" www-data"
owner rwx
group r
all r
我的python应用程序对此日志文件没有读/写权限。但我需要python应用程序才能拥有此权限。
现在手动更改权限很容易,但我需要文件在创建时拥有正确的权限。我怎么能这样做?
my goal:
add python user to group www-date (what is the name of the python user?)
and then:
Owner rwx
Group rwx
all r
答案 0 :(得分:0)
在创建可以执行的文件后,您可以使用os.chmod()来控制给定文件的权限:
os.chmod("/path/to/file", 0o775)
第一个参数是路径,第二个参数是授予权限的标志,您也可以从stat
模块访问标志。