Django: The joined path is located outside of the base path component
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.
Comments
-
ePascoal almost 2 years
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.
-
ePascoal over 7 yearsok my mistake, i real can find my static files, but i don't know why doesn't load any static file when page loads.. and i'm having some difficult to find any error log or some clue why this happen.
-
2ps over 7 yearsMore info add above for you.
-
ePascoal over 7 yearsThanks after search more I did remember that only with a web server running I was able to load static files.