简体   繁体   English

如果文件不存在,则烧瓶创建一个文件

[英]Flask create a file if it doesn't exist

I'm trying to create a file in my flask application, but when the file doesn't already exist, the code fails. 我试图在我的flask应用程序中创建一个文件,但是当该文件不存在时,代码将失败。 I've tried the two typical solutions: 我已经尝试了两种典型的解决方案:

f = open('f.txt', 'a+')

as well as 以及

with open('f.txt', 'a+') as f:
    ...

What am I doing wrong? 我究竟做错了什么?

Use Access Control Lists, instead of opening that directory to everyone. 使用访问控制列表,而不是向所有人打开该目录。

setfacl -m u:flaskuser:rw /some/dir/

Also, check out the documentation on these, it's worth a look : https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/ch-acls.html 另外,请查看这些文档,值得一看: https : //access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/ch-acls.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM