static files suspicious operation, os error, and list of paths

1,789 views
Skip to first unread message

Malik Rumi

unread,
Jul 11, 2016, 9:56:06 PM7/11/16
to Django users
Well, I'm stuck again. I am still trying to get my dev site to work with this new bootstrap theme. Debug toolbar is telling me over 1,000 staticfiles have been found, but none were used. So if they are found, why aren't they used? I ran findstatic and got this traceback:

(cannon)malikarumi@Tetuoan2:~/Projects/cannon/jamf$ python manage.py findstatic /static/bootstrap/css/bootstrap.css
Traceback (most recent call last):
<snip>
  File "/home/malikarumi/Projects/cannon/local/lib/python2.7/site-packages/django/utils/_os.py", line 78, in safe_join
    'component ({})'.format(final_path, base_path))
django.core.exceptions.SuspiciousFileOperation: The joined path (/static/bootstrap/css/bootstrap.css) is located outside of the base path component (/home/malikarumi/Projects/cannon/jamf/static)
(cannon)malikarumi@Tetuoan2:~/Projects/cannon/jamf$


So I took '/static' off the front of the path, because in my settings I have:

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
   
and I thought perhaps that was causing a problem, but it made no difference:   

django.core.exceptions.SuspiciousFileOperation: The joined path (/bootstrap/css/bootstrap.css) is located outside of the base path component (/home/malikarumi/Projects/cannon/jamf/static)

Then, following https://docs.djangoproject.com/en/1.9/ref/settings/#staticfiles-dirs, I made a list of all the paths with bootstrap stuff in them, but then I got a new error:

  File "/home/malikarumi/Projects/cannon/local/lib/python2.7/site-packages/django/core/files/storage.py", line 299, in listdir
    for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/home/Projects/cannon/jamf/static/bootstrap'

Note, the string in STATICFILES_DIRS does have the slash after bootstrap, but that seems to make no difference:

   '/home/Projects/cannon/jamf/static/bootstrap/',
  
Finally, taking yet another look at the docs, I took the os.dir line out and made it another path in the list, but still that made no difference:

  File "/home/malikarumi/Projects/cannon/local/lib/python2.7/site-packages/django/core/files/storage.py", line 299, in listdir
    for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/home/Projects/cannon/jamf/static'

  
Need I also say the directory does in fact exist? What's going on here? Thanks.

ludovic coues

unread,
Jul 11, 2016, 10:57:24 PM7/11/16
to django...@googlegroups.com
Do you define BASE_DIR and STATIC_URL in your settings.py file ?
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4ca8a3ac-9646-4b30-b950-20ac0402f8c5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Malik Rumi

unread,
Jul 12, 2016, 2:47:19 AM7/12/16
to Django users
yes.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_URL = '/static/'

Malik Rumi

unread,
Jul 12, 2016, 7:40:11 AM7/12/16
to Django users
UPDATE:

I got it back to where runserver comes up and I get no errors, but the staticfiles are still not being served.


The paths are in the right format to satisfy the STATICFILES_DIR in SETTINGS, and so that they can be found, according to debug toolbar, and they pass the checks in runserver, collectstatic, and findstatic, but not so they can be used.


I have to assume that safe_join is still running around somewhere in the background, even though it is now failing silently.


I need to make safe join see these paths the same way it saw the single file bootstrap.css when it passed findstatic, but I don't know how to do that.


One could ask why I get all those 404's from runserver, but I think that's explained by the fact that safe_join is still blocking them.


Ideas?

Michal Petrucha

unread,
Jul 12, 2016, 10:03:47 AM7/12/16
to django...@googlegroups.com
On Tue, Jul 12, 2016 at 12:40:11AM -0700, Malik Rumi wrote:
> UPDATE:
>
> I got it back to where runserver comes up and I get no errors, but the
> staticfiles are still not being served.
>
>
> The paths are in the right *format* to satisfy the STATICFILES_DIR in
> SETTINGS, and so that they can be *found*, according to debug toolbar, and
> they *pass* the checks in runserver, collectstatic, and findstatic, but not
> so they can be *used*.
>
>
> I have to assume that safe_join is still running around somewhere in the
> background, even though it is now failing silently.
>
>
> I need to make safe join see these paths the same way it saw the single
> file bootstrap.css when it passed findstatic, but I don't know how to do
> that.
>
>
> One could ask why I get all those 404's from runserver, but I think that's
> explained by the fact that safe_join is still blocking them.
>
> Ideas?

Could you please post all the settings that are in any way related to
static files in full? That means things like STATICFILES_*, and
everything that's used in those (like BASE_DIR, etc). Please, don't
leave any part of them out. If you are not certain, just post the
entire settings module, only remove secret values.

Also, could you provide the exact URL of a request that is resulting
in a SuspiciousFileOperation, including a full traceback?

Based on the error message you posted in the initial post, it looks
like somewhere, you're calling ``os.path.join(a, b)``, where the
second argument starts with a slash – that might be the reason, but
it's hard to tell whether this is the case, because you haven't shown
us the full settings.

Cheers,

Michal
signature.asc

Malik Rumi

unread,
Jul 12, 2016, 9:38:12 PM7/12/16
to django...@googlegroups.com
Michal,


> , it looks like somewhere, you're calling ``os.path.join(a, b)``, where the second argument starts with a slash

I've tried it both ways. The way I got findstatic to work was by taking off the leading slash, but so far I haven't figured out how to make that work so that the files are called.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'essell',
    'csvimport2',
    'debug_toolbar',
    'account',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    os.path.join(BASE_DIR, 'static/bootstrap'),
    os.path.join(BASE_DIR, 'static/bootstrap/css/'),
    os.path.join(BASE_DIR, 'static/bootstrap/fonts/'),
    os.path.join(BASE_DIR, 'static/bootstrap/js/'),
    os.path.join(BASE_DIR, 'static/css/'),
    os.path.join(BASE_DIR, 'static/email_templates/'),
    os.path.join(BASE_DIR, 'static/fonts/'),
    os.path.join(BASE_DIR, 'static/images/'),
    os.path.join(BASE_DIR, 'static/js/'),
    os.path.join(BASE_DIR, 'static/less/'),
    os.path.join(BASE_DIR, 'static/plugins/'),
    os.path.join(BASE_DIR, 'static/videos/'),
]

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'





--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/MoWUYN4SJmk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--

"Every time you see a black kid wearing a hoodie, you say: There's a thug. If you see a white kid wearing hoodie, you say: There's Mark Zuckerberg," Jones told USA TODAY last year.

"I said, 'That's because of racism. And Prince said, 'Maybe so, or maybe you civil rights guys haven't created enough Mark Zuckerbergs.' " 

Michal Petrucha

unread,
Jul 14, 2016, 6:19:48 AM7/14/16
to django...@googlegroups.com
On Tue, Jul 12, 2016 at 02:36:41PM -0700, Malik Rumi wrote:
> Michal,
>
> > , it looks like somewhere, you're calling ``os.path.join(a, b)``, where
> the second argument starts with a slash
>
> I've tried it both ways. The way I got findstatic to work was by taking off
> the leading slash, but so far I haven't figured out how to make that work
> so that the files are called.

I'm afraid I still don't have enough information to help you – you
still haven't provided the other details I asked for in my previous
email, i.e. the URL of a failing request, and a full traceback. While
we're at it, showing how you are referencing static files in your
templates wouldn't hurt either.

In the meantime, just two observations.
Do you have any specific reason to make those static files available
in two locations? As in, your videos will be available in both
/static/videos/some-video.wtf, and /static/some-video.wtf. Your
bootstrap assets will be available in three locations (/static/,
/static/bootstrap/, /static/bootstrap/whatever/). I fail to see how
that will lead to anything other than confusion and problems... You
might want to remove everything but the first element in this list,
and always use the full /static/somedir/another/somefile.ext paths to
reference static files.

> # Simplified static file serving.
> # https://warehouse.python.org/project/whitenoise/
> STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

Since you're using whitenoise, have you tried to follow the setup
instructions at http://whitenoise.evans.io/en/stable/django.html in
their entirety? I'm mostly referring to the middleware.

However, as even the whitenoise docs say, before you start playing
around with whitenoise, you should first make sure your basic
staticfiles setup is correct.

Cheers,

Michal
signature.asc
Reply all
Reply to author
Forward
0 new messages