我有一個 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
提交
取消