I am attempting to make a production build for my application however I am getting an error I do not really understand. The application runs, however an internal server error occurs every time it is accessed from localhost in a browser. This is the stack trace:
[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)
I have created a settings_production.py by following the hellowebapp book available online:
# 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'
I am very confused for why this error is occurring, it seems to have a problem with my jquery file which is in my apps directory. Please request more information if needed to help me find why this error present.
It looks like somewhere in one of your templates you have:
This should be changed to:
You can't pass absolute paths to the
static
tag (though I agree that the resulting error is not very clear!)