【问题标题】:Not found my staticfiles in django 1.9在 django 1.9 中找不到我的静态文件
【发布时间】:2016-04-13 13:54:34
【问题描述】:

我对 Django 有一点问题,它不是我的静态文件。 我已经阅读了文档,我尝试直接放置路径,使用 {{ STATIC_URL }},最推荐的方法是留下细节。知道如何解决吗? 模板.html:

{% load staticfiles %}
    <link rel="stylesheet" type="text/css" href="{% static 'css/normalize.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'css/demo.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'css/component.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'css/cs-select.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'css/cs-skin-boxes.css' %}" />

local.py(设置)

STATIC_URL = '/static/'

STATICFILES_DIRS = [BASE_DIR2.child('static')]

我的文件夹在正确的方向 The first folder is the virtualenv, the second folder is for Django Project where is the manage.py (image)

视图、模型、网址和表单正常工作,并显示所选模板 [python代码正常运行(图)][2]

更新

我尝试为此更改 STATICFILES_DIRS:

STATICFILES_DIRS = (
    os.path.join(os.path.dirname(BASE_DIR), 'static', ),
)

并打印路径以确保它正确,但错误仍在继续。 The result of print 提前致谢

【问题讨论】:

  • 我为 Django 1.9 解决的问题是:STATICFILES_DIRS = (BASE_DIR, 'static')

标签: python django-templates django-staticfiles


【解决方案1】:

我已经为 Django 1.9 解决了:STATICFILES_DIRS = (BASE_DIR, 'static')

【讨论】:

  • 也适用于 django 1.10 ;)
【解决方案2】:

首先,我将 STATICFILES_DIRS 设为一个元组。

接下来,我会尝试这样的格式:

STATICFILES_DIRS = (
    os.path.join(os.path.dirname(BASE_DIR), 'static', 'static_dirs'),
)

为确保它进入正确的目录,print 路径并进行相应调整:

print os.path.join(os.path.dirname(BASE_DIR), 'static', 'static_dirs')

希望有帮助!

【讨论】:

  • 您好,非常感谢您花时间给我一个想法。不幸的是,不工作。 Imprimi 路线,并且正确,但不起作用。 (我留下控制台的截图。)还有其他想法吗?
  • @RRenéAlcántara 你的STATIC_ROOT 是如何配置的?尝试做类似的事情:STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static', 'static')。另外,看看我提供的这个答案。也许尝试模仿设置:stackoverflow.com/questions/29957604/…
  • 抱歉,没有成功。它已经设置了根,所以我把他所说的放在你传递给我的链接中。 STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static') 但是,它不起作用,我标记了错误,说如果使用 root 则不能使用 STATICFILES_DIRS。我还在调查,但什么也没找到。还有其他想法吗?感谢您的宝贵时间。
【解决方案3】:

我已经在 mac 上解决了这个问题:

STATICFILES_DIRS = [os.path.join(os.path.dirname(__file__), 'static').replace('\\','/'),]

【讨论】:

    猜你喜欢
    • 2016-06-01
    • 2017-10-20
    • 2020-05-05
    • 2021-08-27
    • 2014-11-10
    • 2011-08-26
    • 2020-06-22
    • 2021-08-16
    相关资源
    最近更新 更多