简体   繁体   English

heroku应用程序中未提供静态文件

[英]static file not served in heroku app

I deployed my final working project to heroku. 我将最后的工作项目部署到了​​Heroku。

The problem is only html content loading, Static files are missing. 问题仅在于html内容加载,缺少静态文件。 I tried lots but missing something. 我尝试了很多,但缺少了一些东西。 Can you spot the error. 您能发现错误吗?

# .. 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',
)

You must give the STATIC_ROOT ...(It can not be empty). 您必须提供STATIC_ROOT ...(不能为空)。 Because the "HEROKU", always run 'collectstatic' while deploying.. and it creates the folder like as 'static files' and all the process running by the way of this folder contents. 因为“ HEROKU”在部署时始终运行“ collectstatic”,所以它会像“静态文件”一样创建该文件夹,并通过此文件夹的内容来运行所有进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM