gpt4 book ai didi

python - Django 找不到静态文件

转载 作者:太空宇宙 更新时间:2023-11-04 06:11:11 29 4
gpt4 key购买 nike

我对静态文件的设置是这样的

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

在我的 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 %}

        {% 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 %}

当我尝试加载页面时,我在加载资源和日志中看到 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

我在这里缺少什么?

我该如何解决这个问题?

最佳答案

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/',
)

关于python - Django 找不到静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18679251/

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