7

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

perpetualdarkness
  • 135
  • 1
  • 4
  • 18

2 Answers2

7

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/'
Jota
  • 697
  • 10
  • 24
0

I recently faced this error but it‘s actually simple:

Chances are you downloaded a Template, here is the solution: First you have to check your css file for stuff like relative links

For example your CSS might be referencing a file outside your django project itself.

e.g. backround:url('...\image\Profile.jpg') this actually worked for me

Note:
The key fact is just to check your CSS or (maybe js) file first if it‘s a referencing file that you‘re not using or file that is referring to something that is not in your django project directory.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129