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.
findstatic
’s positional argument is the parameter you would pass tostatic
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 thestatic
function in a template. Are you sure you didn’t mean something like:for a file you would refer to with
or
for a file you would refer to with
For your reference:
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:
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.