我正在尝试为我的应用程序制作生产版本,但是我收到的错误我并不理解。应用程序运行,但每次从浏览器中的localhost访问时都会发生内部服务器错误。这是堆栈跟踪:
[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_production.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'
我对此错误发生的原因感到非常困惑,我的jquery文件似乎存在于我的apps目录中。如果需要,请提供更多信息,以帮助我找出出现此错误的原因。
答案 0 :(得分:2)
它看起来像你的一个模板中的某个地方:
{% static '/js/jquery.js' %}
这应该改为:
{% static 'js/jquery.js' %}
您无法将绝对路径传递给static
标记(尽管我同意产生的错误不是很清楚!)