[英]Django image upload is not working
我正在嘗試通過Django管理網站上傳圖片。 但它沒有用,我已經安裝了PIL軟件包。 但它顯示: <django.core.files.storage.FileSystemStorage object at 0x8a92f0c>/mcDonalds.jpg
from django.core.files.storage import FileSystemStorage
projectDirPath = path.dirname(path.dirname(__file__))
storeImageDir = FileSystemStorage(location=projectDirPath + '/couponRestApiApp/static')
storeImage = models.ImageField(upload_to=storeImageDir)
而且靜態目錄為空..我在做錯什么嗎...
試試這個: storeImage = models.ImageField(upload_to="images")
這會將您的文件名ex:abc.png附加到images / abc.png,然后設置要存儲圖像的媒體目錄,例如: yourAppDIR/static/images/....
並設置URL:
url(r'^tosomeThing/(?P<path>.*)/$', 'django.views.static.serve',
{'document_root': MEDIA_URL, 'show_indexes': False}),
在您的設置文件中設置媒體URL。
MEDIA_URL = projectDirPath + '/couponRestApiApp/static/'
當您上傳任何圖像時,它將被存儲在應用程序的圖像目錄中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.