python - Django 找不到静态文件

标签 python django django-templates

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

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/

相关文章:

Python - 基于键/值标识的分组/合并字典

python - 数字 : How can I improve this code to find the number of divisors of big numbers? 的除数

python - 在 pd 数据框中查找与给定列表中的日期匹配的日期

python - NOT NULL 约束失败 : portal_visitrequests. guest_id

python - 如何使用 Python 字符串格式将表示美分的整数转换为表示美元的 float ?

python - 更改时间戳的 utcoffset

django - 在 Django 中管理多个应用程序的静态文件

python - Django + Eclipse,外壳问题

python - Django:如何从 .css 文件链接到静态文件目录?

django-templates - 模板不存在于/