【问题标题】:Error in Displaying the content of a txt file through Django通过 Django 显示 txt 文件的内容时出错
【发布时间】:2020-04-17 15:47:45
【问题描述】:

[这是我要在浏览器屏幕中投影的文本文件。

第二个是具有该功能的视图文件。 path('ShowFile', views.ShowFile, name ='ShowFile') in the last picture in the urls.py

【问题讨论】:

    标签: python django


    【解决方案1】:

    您可以使用这样的函数,根据需要替换路径。

    def ShowFile(request):
        f = open("C:\\Users\\Soumyaranjan\\PycharmProjects\\Textutils\\textutils\\textutils\\one.txt", "r")
        content = f.readlines()
        return HttpResponse(content)
    

    【讨论】:

      猜你喜欢
      • 2018-08-07
      • 2013-10-23
      • 1970-01-01
      • 2011-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多