【问题标题】:django stylesheet donot link with the image filedjango 样式表不与图像文件链接
【发布时间】:2015-01-05 16:05:48
【问题描述】:

在我的 settings.py 中,我有这样的静态设置:

STATIC_ROOT = ' '

STATIC_URL = '/static/'
STATICFILES_DIRS = (

os.path.join(BASE_DIR, 'static'),
)

STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

我的项目结构是:

ProjectName
    app1
    app2
    ProjectName
    static
        css
        js
        images

我在 style.css 中写了一个 css :

input.search { width: 279px; border: none; background: #fff url(../images/input.gif) no-repeat; padding: 6px 10px; color: #1E67A8; font-weight: bold; }

当我这样做时,它没有显示我在 style.css 中分配的图像..

什么问题??

【问题讨论】:

  • 告诉你是否可以通过 url 访问它...? localhost:8000/static/images/input.gif
  • 是的,图片是从提到的网址访问的......
  • 然后在 css 中做同样的事情 .. 见下面我的答案

标签: css django templates static


【解决方案1】:

你可能在你的 settings.py 中需要这个

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

【讨论】:

    【解决方案2】:

    您可以像访问 CSS 中的图像 URL

    input.search { width: 279px; border: none; background: #fff url(/static/images/input.gif) no-repeat; padding: 6px 10px; color: #1E67A8; font-weight: bold; }
    

    【讨论】:

      猜你喜欢
      • 2010-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多