[英]Django could not find the static files
My settings for static files look like 我的静态文件设置如下所示
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/var/lib/openshift/<app_id>/app-root/runtime/repo/static',
)
and in my index.html
I try to get them as 在我的index.html
我尝试将它们作为
{% block javascript %}
<!--script type="text/javascript" src="../static/js/bootstrap.js"></script-->
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="../static/js/slides.js"></script>
{% endblock %}
and 和
{% block css %}
<link rel="stylesheet" href="../static/css/bootstrap.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="../static/css/index.css" type="text/css" media="screen" title="no title" charset="utf-8">
{% endblock %}
When I try to load the page, I see HTTP 500
in loading the resources and in logs I see 尝试加载页面时,在加载资源和日志中看到HTTP 500
Traceback (most recent call last):
File "/opt/rh/python27/root/usr/lib64/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/staticfiles/handlers.py", line 68, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/staticfiles/handlers.py", line 58, in get_response
return self.serve(request)
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/staticfiles/handlers.py", line 51, in serve
return serve(request, self.file_path(request.path), insecure=True)
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/staticfiles/views.py", line 35, in serve
absolute_path = finders.find(normalized_path)
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/staticfiles/finders.py", line 237, in find
for finder in get_finders():
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/staticfiles/finders.py", line 252, in get_finders
yield get_finder(finder_path)
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/utils/functional.py", line 27, in wrapper
result = func(*args)
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/staticfiles/finders.py", line 274, in _get_finder
return Finder()
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python/virtenv/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/contrib/staticfiles/finders.py", line 59, in __init__
if os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
File "/var/lib/openshift/51d9d4d3e0b8cd1e6d0000fd/python//virtenv/lib64/python2.7/posixpath.py", line 356, in abspath
cwd = os.getcwd()
OSError: [Errno 2] No such file or directory
What is that I am missing here? 我在这里想念什么?
How can I fix this issue? 如何解决此问题?
apending a /
after static
solved the issue static
解决问题后附加一个/
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/var/lib/openshift/<app_id>/app-root/runtime/repo/static/',
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.