django 异常值:_getfullpathname:path应为字符串、字节或os,PathLike,而不是list

bwntbbo3  于 2023-05-30  发布在  Go
关注(0)|答案(3)|浏览(267)

我不知道是什么问题,我尝试了一切,但从来没有理解,我应该怎么做,在这种情况下,请看看

Setting.py当我这样做时:

STATIC_URL = '/static/'
    STATICFILES_DIRS = os.path.join(BASE_DIR, 'static')
    
    MEDIA_URL ='/images/'
    MEDIA_ROOT =  os.path.join(BASE_DIR, 'static/images')

显示此错误

ERRORS:
    ?: (staticfiles.E001) The STATICFILES_DIRS setting is not a tuple or list.
            HINT: Perhaps you forgot a trailing comma?

Setting.py当我这样做时:

STATIC_URL = '/static/'
    STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
    
    MEDIA_URL ='/images/'
    MEDIA_ROOT =  [os.path.join(BASE_DIR, 'static/images'),]

显示此错误

TypeError: _getfullpathname: path should be string, bytes or os.PathLike, not list
    [17/Mar/2021 13:27:59] "POST /admin/admission/personal/add/ HTTP/1.1" 500 211689

有谁能帮忙吗?

bmvo0sr5

bmvo0sr51#

尝试

STATIC_URL = '/static/'
#STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]

MEDIA_URL ='/images/'
MEDIA_ROOT =  [os.path.join(BASE_DIR, '*yourappname*/static/images'),]
ev7lccsx

ev7lccsx2#

MEDIA_URL ='/images/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images/')

差仅为images的末尾处的/,即images/

cvxl0en2

cvxl0en23#

在我的情况下,我删除了这个[]括号,它为我工作!
问题:MEDIA_ROOT = [os.path.join(BASE_DIR,'media')]
为我解答:os.path.join(BASE_DIR,'media')
只需删除[]括号

相关问题