Django 在 IIS 上设置媒体文件

我有一个 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'


长风秋雁
浏览 84回答 1
1回答

弑天下

我找到了解决方法。'''从 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))'''
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python