我有一个 Django 应用程序,它在服务器上创建 PDF 文件。在开发服务器上运行良好,但在 IIS 上它不创建文件。我已经给予了所有许可,但没有运气。我写了一个简单的脚本来写一个文本文件,但在 IIS 上也不起作用。解决此问题的任何帮助都适用。谢谢。 def fileWriteTest(request): f = open("media/testwrite.txt", "a") f.write("Now the file has more content!") f.close() print("File Written!") return HttpResponse("Done !")/accounts/testfile/ 处的 FileNotFoundError [Errno 2] 没有这样的文件或目录:'media/testwrite.txt'
1 回答

弑天下
TA贡献1818条经验 获得超8个赞
我找到了解决方法。
'''
从 django.conf 导入设置导入操作系统
def fileWriteTest(请求):
my_file = os.path.join(settings.MEDIA_ROOT, str("testwrite4.txt"))
f = open(my_file, "a")
f.write("Now the file has more content!")
f.close()
print("File Written!")
return HttpResponse(str(my_file))
'''
添加回答
举报
0/150
提交
取消