Django显示上传文件内容 [英] Django displaying upload file content
问题描述
我有一个应用程序,可以将不同的文档加载到服务器上,并允许用户阅读文档的内容.我正在将文档上传到服务器,然后尝试按id读取课程,例如:
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)
等
但是我什么都没找到:如何实际读取/.doc/.pdf/.txt的内容并将其显示在网页上?
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?
推荐答案
读取纯文本文件很简单,而PDF和Word处理则不然.对于后两个,您将必须合并一些外部库.
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.
-
文本:
f.read()
Word:从python中的MS字文件中提取文本
PDF: http://www.unixuser.org/~euske/python/pdfminer/index.html
这篇关于Django显示上传文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!