【问题标题】:OSError: [Errno 2] No such file or directory: '/tmp/MakeCalls/Static'OSError:[Errno 2] 没有这样的文件或目录:'/tmp/MakeCalls/Static'
【发布时间】:2017-06-13 18:25:01
【问题描述】:

在执行“git push heroku master”(来自 Django 应用程序)时,推送被拒绝。我在下面包含了回溯。我可以禁用 collectstatic 但网页中缺少所有静态文件。

当我在本地服务器上运行python manage.py collectstatic --noinput 时,它不会出现任何错误。我在过去的两天里一直在做这件事,不知道我做错了什么。我在下面包含了我的.settings 用于静态文件。我正在使用白噪声,它在我的本地主机上运行良好。

我认为这与未找到的相对路径有关。但这不可能,因为我的本地服务器上没有错误?

remote:      $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 10, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
remote:            collected = self.collect()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
remote:            for path, storage in finder.list(self.ignore_patterns):
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
remote:            for path in utils.get_files(storage, ignore_patterns):
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
remote:            directories, files = storage.listdir(location)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py", line 299, in listdir
remote:            for entry in os.listdir(path):
remote:        OSError: [Errno 2] No such file or directory: '/tmp/MakeCalls/Static'
remote:
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote:
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote:
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1

静态文件:

STATICFILES_DIRS = ([
    os.path.join(os.path.dirname(BASE_DIR), 'MakeCalls', 'Static'),    
])

STATIC_URL = '/Static/'

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'MakeCalls', 'MakeCalls', 'Static')



MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')

MEDIA_URL = os.path.join(BASE_DIR, 'media/')


STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

【问题讨论】:

    标签: django heroku


    【解决方案1】:

    所以我设法自己解决了这个问题。问题是我所有的静态文件都组织在root/Static 中,并与STATICFILES_DIRS 一起提供。但是,由于某种原因,Heroku 无法阅读此内容。所以我把所有的静态文件放在root/app/static 中,并在设置中删除了STATICFILES_DIRS,一切都奏效了!

    【讨论】:

    • 所以我注释掉了“STATICFILES_DIRS”,它运行良好,这有什么缺点吗?
    • 我想@Calco,因为不会有一个中心位置来放置通用或非应用程序特定的静态文件,例如,将单页应用程序的静态文件捆绑到特定位置,在这个静态文件夹中,Django 可以从中找到额外的静态文件以供使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 2012-07-18
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    相关资源
    最近更新 更多