gpt4 book ai didi

python - Django Web 应用程序的生产构建在访问时引发 SuspiciousFileOperation

转载 作者:行者123 更新时间:2023-12-01 02:38:16 29 4
gpt4 key购买 nike

我正在尝试为我的应用程序进行生产构建,但是我收到了一个我不太理解的错误。该应用程序运行,但是每次从浏览器中的本地主机访问它时都会发生内部服务器错误。这是堆栈跟踪:

[2017-09-01 17:34:07 +0100] [5301] [INFO] Starting gunicorn 19.7.1
[2017-09-01 17:34:07 +0100] [5301] [INFO] Listening at: http://127.0.0.1:8000 (5301)
[2017-09-01 17:34:07 +0100] [5301] [INFO] Using worker: sync
[2017-09-01 17:34:07 +0100] [5304] [INFO] Booting worker with pid: 5304
[2017-09-01 16:34:16 +0000] [5304] [ERROR] Error handling request /
Traceback (most recent call last):
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
self.handle_request(listener, req, client, addr)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/whitenoise/base.py", line 66, in __call__
return self.application(environ, start_response)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
response = self.get_response(request)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response
response = self._middleware_chain(request)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 44, in inner
response = response_for_exception(request, exc)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 86, in response_for_exception
response = get_exception_response(request, get_resolver(get_urlconf()), 400, exc)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 116, in get_exception_response
response = handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 143, in handle_uncaught_exception
return callback(request, **param_dict)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/views/defaults.py", line 74, in server_error
return http.HttpResponseServerError(template.render())
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/backends/django.py", line 66, in render
return self.template.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 208, in render
return self._render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 994, in render
bit = node.render_annotated(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 961, in render_annotated
return self.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/loader_tags.py", line 174, in render
return compiled_parent._render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 994, in render
bit = node.render_annotated(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 961, in render_annotated
return self.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/templatetags/static.py", line 104, in render
url = self.url(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/templatetags/static.py", line 101, in url
return self.handle_simple(path)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/templatetags/static.py", line 114, in handle_simple
return staticfiles_storage.url(path)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 132, in url
hashed_name = self.stored_name(clean_name)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 292, in stored_name
cache_name = self.clean_name(self.hashed_name(name))
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 93, in hashed_name
if not self.exists(clean_name):
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/files/storage.py", line 394, in exists
return os.path.exists(self.path(name))
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 52, in path
return super(StaticFilesStorage, self).path(name)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/files/storage.py", line 407, in path
return safe_join(self.location, name)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/utils/_os.py", line 78, in safe_join
'component ({})'.format(final_path, base_path))
SuspiciousFileOperation: The joined path (/js/jquery.js) is located outside of the base path component (/Users/callum/Documents/Tutoring/Tutoring/staticfiles)
[2017-09-01 16:34:17 +0000] [5304] [ERROR] Error handling request /favicon.ico
Traceback (most recent call last):
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
self.handle_request(listener, req, client, addr)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/whitenoise/base.py", line 66, in __call__
return self.application(environ, start_response)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
response = self.get_response(request)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response
response = self._middleware_chain(request)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 44, in inner
response = response_for_exception(request, exc)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 86, in response_for_exception
response = get_exception_response(request, get_resolver(get_urlconf()), 400, exc)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 116, in get_exception_response
response = handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 143, in handle_uncaught_exception
return callback(request, **param_dict)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/views/defaults.py", line 74, in server_error
return http.HttpResponseServerError(template.render())
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/backends/django.py", line 66, in render
return self.template.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 208, in render
return self._render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 994, in render
bit = node.render_annotated(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 961, in render_annotated
return self.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/loader_tags.py", line 174, in render
return compiled_parent._render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 994, in render
bit = node.render_annotated(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/template/base.py", line 961, in render_annotated
return self.render(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/templatetags/static.py", line 104, in render
url = self.url(context)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/templatetags/static.py", line 101, in url
return self.handle_simple(path)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/templatetags/static.py", line 114, in handle_simple
return staticfiles_storage.url(path)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 132, in url
hashed_name = self.stored_name(clean_name)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 292, in stored_name
cache_name = self.clean_name(self.hashed_name(name))
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 93, in hashed_name
if not self.exists(clean_name):
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/files/storage.py", line 394, in exists
return os.path.exists(self.path(name))
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 52, in path
return super(StaticFilesStorage, self).path(name)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/files/storage.py", line 407, in path
return safe_join(self.location, name)
File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/utils/_os.py", line 78, in safe_join
'component ({})'.format(final_path, base_path))
SuspiciousFileOperation: The joined path (/js/jquery.js) is located outside of the base path component (/Users/callum/Documents/Tutoring/Tutoring/staticfiles)

我按照在线提供的 hellowebapp 书籍创建了一个 settings_development.py:

# Inherit from standard settings file for defaults
from tutoring.settings import *

# Everything below will override our standard settings:

# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Set debug to False
DEBUG = False

# Static asset configuration
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'

我很困惑为什么会发生这个错误,我的apps目录中的jquery文件似乎有问题。如果需要帮助我找出出现此错误的原因,请索取更多信息。

最佳答案

它看起来像您的模板之一中的某个位置:

{% static '/js/jquery.js' %}

这应该更改为:

{% static 'js/jquery.js' %}

您无法将绝对路径传递给 static 标记(尽管我同意生成的错误不是很清楚!)

关于python - Django Web 应用程序的生产构建在访问时引发 SuspiciousFileOperation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46004691/

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