gpt4 book ai didi

python - django.core.exceptions.SuspiciousFileOperation : The joined path is located outside of the base path component

转载 作者:太空宇宙 更新时间:2023-11-04 09:37:05 26 4
gpt4 key购买 nike

这每次用于做 django 网站时都很好,但这次它给我一个错误。

设置.py

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

STATIC_ROOT = os.path.join(BASE_DIR , 'static')
STATIC_URL = '/static/'

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

我的目录 Portfolio-Project/Portfolio/static/profile.jpg 中有一个 profile.jpg。它应该从这里收集静态文件并将静态文件粘贴到我的代码中提到的 Portfolio-project/static 中。但它给了我一些错误。

使用命令“Python manage.py collectstatic”后出错

django.core.exceptions.SuspiciousFileOperation: The joined path 
(C:\Users\Kiran\Desktop\portfolio-project\portfolio\static\Profile.jpg) is
located outside of the base path component
(C:\Users\Kiran\Desktop\portfolio- project\portfolio\static\)

请帮助。谢谢

最佳答案

在你的行中:

os.path.join(BASE_DIR, 'portfolio/static/')

删除最后一个斜线:

 os.path.join(BASE_DIR, 'portfolio/static')

无论如何,这是理想的:

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)

STATIC_URL = '/static/'

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

关于python - django.core.exceptions.SuspiciousFileOperation : The joined path is located outside of the base path component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53246297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com