【问题标题】:static file not served in heroku app静态文件未在 heroku 应用程序中提供
【发布时间】:2014-06-30 20:39:39
【问题描述】:

我将我的最终工作项目部署到 heroku。

问题只是 html 内容加载,缺少静态文件。我尝试了很多但错过了一些东西。你能发现错误吗?

# .. settings.py

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

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.
    os.path.join(BASE_DIR, 'static/'),
)

STATIC_ROOT = ''

STATIC_URL = '/static/'

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates/'),
)

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

【问题讨论】:

    标签: python django heroku django-templates


    【解决方案1】:

    你必须给 STATIC_ROOT ...(不能为空)。因为“HEROKU”,在部署时总是运行“collectstatic”。它创建的文件夹就像“静态文件”一样,所有的进程都通过这个文件夹的内容运行。

    【讨论】:

      猜你喜欢
      • 2014-10-25
      • 2021-12-30
      • 2017-10-27
      • 2013-01-13
      • 1970-01-01
      • 2016-11-07
      • 2015-01-17
      • 2013-09-04
      • 1970-01-01
      相关资源
      最近更新 更多