【问题标题】:Django/Heroku: favicon renders as dead image when going to example.com/favicon.icoDjango/Heroku:访问 example.com/favicon.ico 时,favicon 呈现为死图像
【发布时间】:2014-11-26 21:57:37
【问题描述】:

我正在 heroku 上运行一个 django 项目。在看到我的 favicon.ico 无法加载后,我决定在访问我的页面 example.com/favicon.ico 时查看它是否正常工作。

我(在多个浏览器上)看到的是这样的死图像:https://app.box.com/s/q9uqb2kmooak93ockvbl

我正在为 favicon.ico 提供服务:

<link rel="shortcut icon" href="{% static 'favicon.ico' %}" type="image/x-icon"/>

另外,我应该提到我正在重定向我的 django 项目中的 url,如下所示:

#serving favicon
(r'^favicon\.ico$', RedirectView.as_view(url='/static/favicon.ico')),

不过这应该没关系。

我想知道这是不是一个问题:

  1. 我正在尝试渲染的图像(虽然我对此表示怀疑,因为其他图像渲染得很好)
  2. heroku 的问题
  3. 还是快捷方式图标参考链接有问题?

以下是我的静态设置:

STATIC_URL = '/static/'

# only refers to the location where your static files should end up after running manage.py collectstatic. you shouldn't really need collectstatic) when developing locally
STATIC_ROOT = 'staticfiles'


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

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(BASE_DIR, '../templates'),
)


# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

有什么想法吗?

【问题讨论】:

标签: python django heroku django-urls favicon


【解决方案1】:

** 根据更新更新**

我会尝试在您的 URL 中删除对 favicon 的特殊调用,并让该图标像任何其他图像一样自行服务。我怀疑你得到了双重重定向。

【讨论】:

  • example.com/static/favicon.ico 是被转发到包含死图像的链接。如果需要,我可以发布 ACTUAL。我也相信我的静态设置是正确的。我已将它们添加到 OP 中。我所有其他静态图像似乎都工作正常..
  • 我需要将我的 favicon.ico 放在我的根目录中吗?还是只使用 并将其保留在原处?双重重定向是否重要?
  • 你可能会把它放在你的静态图像中,因为你说那是它渲染的地方。
猜你喜欢
  • 2020-06-03
  • 2018-12-19
  • 2020-09-03
  • 2016-01-01
  • 2023-03-06
  • 2015-08-28
  • 2019-03-10
  • 2020-05-17
  • 1970-01-01
相关资源
最近更新 更多