您可以通过模型浏览存储的文件。
假设你的模型,声明如下
import os
class Document(models.Model):
name = models.CharField(max_length=64)
doc_file = models.FileField(upload_to='documents')
你可以得到的文件就像任何其他领域
names = []
# To browse your saved file, get the containing models
documents = Document.objects.all()
for doc in documents:
# This is how you get the URL of the file field
url = doc.doc_file.url
# If you need the path of the stored file (in the server)
doc_path = doc.doc_file.path
# get name and size of the file
name, size = doc.doc_file.name.split(os.path.sep)[-1], doc.doc_file.size
names.append(name)
#process your file names
...
然后你只是去处理的URL,例如,它显示给你的用户。
我在这台服务器上有应用程序,我希望它在文件上执行一些任务。 Django只是这个操作的GUI。所以我想要做的就是让我选择文件,并将其名称传递给另一个模块。它不能是ssh,因为这个GUI服务其他与这个项目不相关的东西。 – eclipse
你需要在网络上做到这一点? Web浏览器并不擅长访问本地文件内容。尝试使用PyQt或EPD套件来构建桌面应用程序。 –
我很想使用别的东西,但整个项目已经在Django中,并且文件选择是唯一缺失的东西:)而且它也必须是Web应用程序才能提供远程访问。 – eclipse