Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This worked fine everytime used to do django websites but this time it is giving me an error.

Settings.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/'

I have a profile.jpg in my directory Portfolio-Project/Portfolio/static/profile.jpg. It should collectstatic from here and paste the staticfiles in Portfolio-project/static as mentioned in my code. but it is giving ,me some error.

Error After using the command "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\)

Please Help. Thanks

like image 219
perpetualdarkness Avatar asked Nov 11 '18 06:11

perpetualdarkness


Video Answer


1 Answers

In your line:

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

Delete the last slash:

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

Anyway, this is the ideal:

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

STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'
like image 171
Jota Avatar answered Sep 28 '22 07:09

Jota