Django显示上传文件内容 [英] Django displaying upload file content

查看:61
本文介绍了Django显示上传文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可以将不同的文档加载到服务器上,并允许用户阅读文档的内容.我正在将文档上传到服务器,然后尝试按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.

Word:从python中的MS字文件中提取文本

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

这篇关于Django显示上传文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆