python - Django image upload succeeds with url written to DB but no image shows upload target folder -


i have form in django

class businessform(forms.form):     name = forms.charfield( required = true,                              max_length=max_name_length,                                                              widget=forms.textinput(attrs={'placeholder': 'e.g boston market'}))             image = forms.imagefield() 

which belongs model

class business(models.model):     """ describes bussines data type """         name = models.charfield(max_length=bus_name_length)               img = models.imagefield( upload_to = upload_to ) 

where upload_to = 'business/images'

and in settings.py have media root defined follows

# media root - uploaded images media_root = '/uploads/' 

in database after upload through form see urls example following

urls shown in mysql database query

however in filesystem not see file, running in test environment on localhost. using windows os.

empty folder - explorer

why that? have set permissions folder? if so, how make sure work in production when deploy ? thanks.

this happening because media_url , media_root aren't configured properly. put following code in settings.py

media_url = '/uploads/' media_root = os.path.join(base_dir, "uploads") 

note

if base_dir not defined in settings file, put following code on top of file:

import os base_dir = os.path.dirname(os.path.dirname(__file__)) 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -