OSError:[Errno 2]没有这样的文件或目录:' / tmp / MakeCalls / Static'

时间:2017-01-27 23:29:45

标签: django heroku

在做git push heroku master' (来自Django应用程序),推送被拒绝。我在下面列出了追溯。我可以禁用collectstatic,但网页中缺少所有静态文件。

当我在本地服务器上运行python manage.py collectstatic --noinput时,它不会出现任何错误。我过去两天都花在这上面,不知道我做错了什么。我在下面列出了我.settings的静态文件。我正在使用whitenoise,它在我的localhost上运行得非常好。

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

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:

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'

1 个答案:

答案 0 :(得分:8)

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