0

I am trying to upload image through Django admin site. But it is not working i have installed PIL package. But it is displaying : <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)

And the static dir is empty..is i am doing something wrong...

Vaibhav Jain
  • 5,287
  • 10
  • 54
  • 114
  • 1
    First of all, `upload_to` should be set directly to the upload path or to a callable (see [docs](https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to)). Please, also see: http://stackoverflow.com/questions/5135556/dynamic-file-path-in-django. – alecxe Apr 15 '13 at 18:08

1 Answers1

1

Try this : storeImage = models.ImageField(upload_to="images")

This will append your file name ex: abc.png to images/abc.png and then set media dir where you want to store images for ex: yourAppDIR/static/images/....

And set the URL :

url(r'^tosomeThing/(?P<path>.*)/$', 'django.views.static.serve',
     {'document_root': MEDIA_URL, 'show_indexes': False}),

Set media URL in your settings file..to

MEDIA_URL = projectDirPath + '/couponRestApiApp/static/'

when you will upload any image it will get stored in the images dir of your app