Django: The joined path is located outside of the base path component

12.3k views Asked by At

i'm using Django 10 and i dont know why after i collect my static files successfuly, when i try to run server in deployment mode(debug=False) it occurs me something like this:

When i look for a static file by doing: python manage.py findstatic /static/mysite/js/javascript.js

django.core.exceptions.SuspiciousFileOperation: The joined path (/static/mysite/js/javascript.js) is located outside of the base path component (/home/xxxx/.venvs/mysite/local/lib/python2.7/site-packages/django/contrib/admin/static)

I run this using a virtual env 'mysite'.

In settings.py:

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, "static") (i tried also just only 'static')

MEDIA_ROOT = BASE_DIR + '/mysite/media'

MEDIA_URL = '/media/'

my urls.py:

urlpatterns = [   
    url(r'', include('mysite.urls')),
]

urlpatterns += staticfiles_urlpatterns()

This is new for me, i also did already a django website and it never occurs such error. Why is not considering my STATIC_ROOT path? For the other hand the collectstatic works fine. And if i runserver with a debug a true it works like a charm.

1

There are 1 answers

3
2ps On BEST ANSWER

findstatic’s positional argument is the parameter you would pass to static to render a particular static file in a template. The error you are seeing is because you used an absolute path and not the parameter you would pass to the static function in a template. Are you sure you didn’t mean something like:

python manage.py findstatic mysite/js/javascript.js

for a file you would refer to with

{% static 'mysite/js/javascript.js' %}

or

python manage.py findstatic js/javascript.js

for a file you would refer to with

{% static 'js/javascript.js' %}

For your reference:

usage: manage.py findstatic [-h] [--version] [-v {0,1,2,3}]
                            [--settings SETTINGS] [--pythonpath PYTHONPATH]
                            [--traceback] [--no-color] [--first]
                            staticfile [staticfile ...]

Finds the absolute paths for the given static file(s).

positional arguments:   staticfile

n.b., django's staticfiles app is not supposed to be used in production. In production, you are supposed to use a webserver to serve static files based. e.g., for nginx, you would include a block like this:

location /static {
    root /path/to/django;
}

To debug your static files check your STATIC_ROOT directory after you run collectstatic and make sure your files are there. If they are, make sure your webserver is configured to properly serve your static files directory.