您可以通過模型瀏覽存儲的文件。
假設你的模型,聲明如下
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