简体   繁体   中英

Django media not loading, static files working

I'm trying to run a jango site, static files are working, media is not loaded from the media folder, if the picture in static files is visible. The folder is listed correctly, pycharm gives a fall in the folder

setings.py

STATIC_ROOT = '/home/static/'
STATIC_URL = '/static/'

# MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
MEDIA_ROOT = '/home/media/'
MEDIA_URL = '/media/'

urls.py

if settings.DEBUG:
import debug_toolbar

# Server statics and uploaded media
urlpatterns += static(settings.MEDIA_URL,
                      document_root=settings.MEDIA_ROOT)
# Allow error pages to be tested
urlpatterns += [
    url(r'^403$', handler403),
    url(r'^404$', handler404),
    url(r'^500$', handler500),
    url(r'^__debug__/', include(debug_toolbar.urls)),

]

I use django oscar, this can be the cause of the problem?

Perhaps the access to the desired folder is not possible. To do this, you must run the following command:

chown -R $user:www-data /home/media/
or
chmod 755 -r /home/media 

To solve this problem, you should executed pycharm with run as administrator or apache service executed run as administartor ,or Enter the absolute path to the media file like:
"C:\\Users\\dr_r00t3r\\DjangoProject\\media"

Yes, if I use full path to media, it's working. like this:

MEDIA_ROOT = 'F:/Work/Mebli1/backup-7.30.2018_21-56-35_u6487/homedir/furniture/furniture/home/media'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM