Django在IIS上设置媒体文件

2024-09-30 03:24:09 发布

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

我有一个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 !")

FileNotFoundError位于/accounts/testfile/ [Errno 2]没有这样的文件或目录:“media/testwrite.txt”


Tags: 文件django服务器txt脚本应用程序pdfrequest
1条回答
网友
1楼 · 发布于 2024-09-30 03:24:09

我找到了一份工作

'''

从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))

'''

相关问题 更多 >

    热门问题