拒绝Django在生产服务器(Azure)中打开媒体的权限

2024-03-28 14:50:27 发布

您现在位置:Python中文网/ 问答频道 /正文

现在我正在处理生产服务器(AzureWebsites),我想打开我的.txt文件。你知道吗

这是我用来保存stopwords.txt的树

-App
  -media
      -App
         stopwords.txt
  -static
  -templates

设置.py

MEDIA_ROOT = path.join(PROJECT_ROOT, 'media').replace('\\', '/')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'

我想用这个命令打开文本文件

handle = open('/media/stopwords.txt', 'r+')
var = handle.read()

这是我运行应用程序时遇到的错误

[Errno 13] Permission denied: '/media/stopwords.txt'

当我试图用这个

handle = open(settings.MEDIA_ROOT + 'stopwords.txt', 'r+')

我犯了这个错误

[Errno 2] No such file or directory: 'D:/home/site/wwwroot/mediastopwords.txt'

有人能帮忙解决这个问题吗?你知道吗


Tags: 服务器txtcomapphttpurl错误root
2条回答

根据您的树,stopwords存储在/media/App下/停止字.txt 因此,要打开它,您需要:

handle = open(settings.MEDIA_ROOT + '/App/stopwords.txt', 'r+')

试试handle = open(settings.MEDIA_ROOT + '/stopwords.txt', 'r+')

相关问题 更多 >