Python,Django,无根但具有自定义权限的本地文件保存

问题描述

我正在开发Django应用,并尝试使用该功能保存文件

def save_entry(title,content):
    """
    Saves an app entry,given its title and Markdown
    content. If an existing entry with the same title already exists,it is replaced.
    """
    filename = f"entries/{title}.md"
    if default_storage.exists(filename):
        default_storage.delete(filename)
    default_storage.save(filename,ContentFile(content))

我将其保存为具有ROOT权限的

-rw-r--r-- 1 root root    18 Aug 27 12:08  Page_test2.md

相反:

-rwxrwxrwx 1 1000 1000   136 Aug 24 23:16  Python.md*

我的应用未在列表中看到它们 因此,我想

def list_entries():
    """
    Returns a list of all names of encyclopedia entries.
    """
    _,filenames = default_storage.listdir("entries")
    return list(sorted(re.sub(r"\.md$","",filename)
                for filename in filenames if filename.endswith(".md")))

提示我如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)