gpt4 book ai didi

python - django 调试工具栏 - SuspiciousFileOperation : Attempted access to '/static/_img/A/B/image01.png' denied

转载 作者:行者123 更新时间:2023-12-03 09:20:56 25 4
gpt4 key购买 nike

我最近安装了 django-debug-toolbar,但在访问临时服务器上的静态文件时遇到问题。错误信息:

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.

只有当我将设置更改为 DEBUG = True 时,才会出现错误消息。我不认为这是静态文件夹的文件夹权限问题,因为当 DEBUG = False 时图像加载正常。

如果需要更多信息,请告诉我。

编辑我已经发布了正确的回溯。

静态文件配置(来自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"
)

最佳答案

我在我们的舞台服务器上遇到了同样的问题。我将 DEBUG_TOOLBAR_​​PANELS 添加到设置文件中,并删除了相对于默认值的 debug_toolbar.panels.staticfiles.StaticFilesPanel 项。这只是在找到更好的解决方案之前的一种解决方法。

下面是我添加到设置中的DEBUG_TOOLBAR_​​PANELS:

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',
]

关于python - django 调试工具栏 - SuspiciousFileOperation : Attempted access to '/static/_img/A/B/image01.png' denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31396715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com