Django displaying upload file content

两盒软妹~` 提交于 2019-12-11 05:55:59

问题


I have an application that loads different documents to the server, and allows users to read documents' content. I am uploading the documents to the server, and then I try to read the courses by id, like:

 def view_course(request,id):
  u = Courses.objects.get(pk=id)

etc

But I don't find anywhere: how can I actually read the content of a /.doc/.pdf/.txt and display it on a web page?


回答1:


Reading plain text files is trivial, while PDF and Word processing is not. For the latter two you'll have to incorporate some external libraries.

  • Text: f.read()

  • Word: extracting text from MS word files in python

  • PDF: http://www.unixuser.org/~euske/python/pdfminer/index.html



来源:https://stackoverflow.com/questions/2983971/django-displaying-upload-file-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!