2

I recently installed django-debug-toolbar and am having trouble accessing static files on my staging server. The error message:

SuspiciousFileOperation at /home/
Attempted access to '/static/_img/A/B/image01.png' denied.



Traceback:
File "/home/code/venv/X/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
  204.                 response = middleware_method(request, response)
File "/home/code/venv/X/lib/python3.4/site-packages/debug_toolbar/middleware.py" in process_response
  129.             bits[-2] += toolbar.render_toolbar()
File "/home/code/venv/X/lib/python3.4/site-packages/debug_toolbar/toolbar.py" in render_toolbar
  64.             return render_to_string('debug_toolbar/base.html', context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/loader.py" in render_to_string
  172.         return t.render(Context(dictionary))
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  148.             return self._render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/test/utils.py" in instrumented_test_render
  88.     return self.nodelist.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render_node
  858.         return node.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/defaulttags.py" in render
  208.                         nodelist.append(node.render(context))
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/defaulttags.py" in render
  312.                 return nodelist.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render_node
  858.         return node.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/defaulttags.py" in render
  312.                 return nodelist.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render_node
  858.         return node.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  898.             output = self.filter_expression.resolve(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in resolve
  596.                 obj = self.var.resolve(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in resolve
  734.             value = self._resolve_lookup(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in _resolve_lookup
  770.                         current = getattr(current, bit)
File "/home/code/venv/X/lib/python3.4/site-packages/debug_toolbar/panels/__init__.py" in content
  96.             return render_to_string(self.template, self.get_stats())
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/loader.py" in render_to_string
  172.         return t.render(Context(dictionary))
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  148.             return self._render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/test/utils.py" in instrumented_test_render
  88.     return self.nodelist.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render_node
  858.         return node.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/defaulttags.py" in render
  312.                 return nodelist.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render_node
  858.         return node.render(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/defaulttags.py" in render
  208.                         nodelist.append(node.render(context))
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in render
  898.             output = self.filter_expression.resolve(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in resolve
  596.                 obj = self.var.resolve(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in resolve
  734.             value = self._resolve_lookup(context)
File "/home/code/venv/X/lib/python3.4/site-packages/django/template/base.py" in _resolve_lookup
  788.                             current = current()
File "/home/code/venv/X/lib/python3.4/site-packages/debug_toolbar/panels/staticfiles.py" in real_path
  34.         return finders.find(self.path)
File "/home/code/venv/X/lib/python3.4/site-packages/django/contrib/staticfiles/finders.py" in find
  249.         result = finder.find(path, all=all)
File "/home/code/venv/X/lib/python3.4/site-packages/django/contrib/staticfiles/finders.py" in find
  159.             match = self.find_in_app(app, path)
File "/home/code/venv/X/lib/python3.4/site-packages/django/contrib/staticfiles/finders.py" in find_in_app
  173.             if storage.exists(path):
File "/home/code/venv/X/lib/python3.4/site-packages/django/core/files/storage.py" in exists
  265.         return os.path.exists(self.path(name))
File "/home/code/venv/X/lib/python3.4/site-packages/django/core/files/storage.py" in path
  281.             raise SuspiciousFileOperation("Attempted access to '%s' denied." % name)

Exception Type: SuspiciousFileOperation at /A/
Exception Value: Attempted access to '/static/_img/A/B/image01.png' denied.

The error message only occurs as soon as I change the setting to DEBUG = True. I don't think it's a folder permissions issue to the static folder as the images load fine when DEBUG = False.

Please let me know if more info is needed.

edit I've posted the correct traceback.

static files config (from settings.py):

STATIC_URL = "/static/"
STATICFILES_DIR = ( "/var/www/html/static", )
STATIC_ROOT = os.path.join(BASE_DIR, "static")

INSTALLED_APPS = (
...
"django.contrib.staticfiles",
...
)

STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"django.contrib.staticfiles.finders.FileSystemFinder",
"compressor.finders.CompressorFinder"
)
user673869
  • 221
  • 1
  • 3
  • 10

2 Answers2

4

I had the same issue on our stage server. I added the DEBUG_TOOLBAR_PANELS to the settings file and removed the debug_toolbar.panels.staticfiles.StaticFilesPanel item with respect to the defaults. It's just a workaround before a better solution is found out.

Below is the DEBUG_TOOLBAR_PANELS I added to the settings:

DEBUG_TOOLBAR_PANELS = [
    'debug_toolbar.panels.versions.VersionsPanel',
    'debug_toolbar.panels.timer.TimerPanel',
    'debug_toolbar.panels.settings.SettingsPanel',
    'debug_toolbar.panels.headers.HeadersPanel',
    'debug_toolbar.panels.request.RequestPanel',
    'debug_toolbar.panels.sql.SQLPanel',
    'debug_toolbar.panels.templates.TemplatesPanel',
    'debug_toolbar.panels.cache.CachePanel',
    'debug_toolbar.panels.signals.SignalsPanel',
    'debug_toolbar.panels.logging.LoggingPanel',
    'debug_toolbar.panels.redirects.RedirectsPanel',
    'debug_toolbar.panels.profiling.ProfilingPanel',
]
aboger
  • 2,214
  • 6
  • 33
  • 47
Abed
  • 131
  • 1
  • 3
1

I'm having the issue right now on a localy launched project in debug mode. I think that there is one function that prepend a backslash and it should not. The error can be reproduced and compared with the right relative filename using this:

python3 manage.py findstatic /css/bootstrap.min.css
python3 manage.py findstatic css/bootstrap.min.css

There is a change that you have a template wrong: For example

<link href="{% static '/css/bootstrap.min.css' %}" rel="stylesheet">

instead of

<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
Rolandf
  • 1,647
  • 1
  • 11
  • 10