Django 尝试在Heroku上收集静态文件时,没有此类文件或目录

Django 尝试在Heroku上收集静态文件时,没有此类文件或目录,django,heroku,amazon-s3,django-settings,collectstatic,Django,Heroku,Amazon S3,Django Settings,Collectstatic,我正在尝试向我在Heroku上部署的Django应用程序添加一个静态文件目录(包含javascript、css等) 存储是用AWS S3完成的,我知道这部分工作正常,因为在尝试添加此静态目录之前,commandheroku run python manage.py collectstatic工作正常,将管理站点的所有资产放在我的AWS S3存储桶中 基本上,我在项目的主应用程序的同一级别添加了一个名为“static”的目录,称为“core”。我希望当我运行collectstatic时,这个目录中

我正在尝试向我在Heroku上部署的Django应用程序添加一个静态文件目录(包含javascript、css等)

存储是用AWS S3完成的,我知道这部分工作正常,因为在尝试添加此静态目录之前,command
heroku run python manage.py collectstatic
工作正常,将管理站点的所有资产放在我的AWS S3存储桶中

基本上,我在项目的主应用程序的同一级别添加了一个名为“static”的目录,称为“core”。我希望当我运行collectstatic时,这个目录中的文件将类似地放在我的AWS S3 bucket中的“static”下

但这就是我在Heroku上部署应用程序时得到的结果

 (primedminds-FA7a2hIW) bash-3.2$ git push heroku master
 Counting objects: 2, done.
 Delta compression using up to 4 threads.
 Compressing objects: 100% (2/2), done.
 Writing objects: 100% (2/2), 236 bytes | 236.00 KiB/s, done.
 Total 2 (delta 1), reused 0 (delta 0)
 remote: Compressing source files... done.
 remote: Building source:
 remote: 
 remote: -----> Python app detected
 remote:  !     The latest version of Python 3.6 is python-3.6.6 (you are using python-3.6.5, which is unsupported).
 remote:  !     We recommend upgrading by specifying the latest version (python-3.6.6).
 remote:        Learn More: https://devcenter.heroku.com/articles/python-runtimes
 remote:        Skipping installation, as Pipfile.lock hasn't changed since last deploy.
 remote: -----> $ python manage.py collectstatic --noinput
 remote:        /app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
 remote:          """)
 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/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
 remote:            utility.execute()
 remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
 remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
 remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
 remote:            self.execute(*args, **cmd_options)
 remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
 remote:            output = self.handle(*args, **options)
 remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 189, in handle
 remote:            collected = self.collect()
 remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 105, in collect
 remote:            for path, storage in finder.list(self.ignore_patterns):
 remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/finders.py", line 125, in list
 remote:            for path in utils.get_files(storage, ignore_patterns):
 remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
 remote:            directories, files = storage.listdir(location)
 remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 313, in listdir
 remote:            for entry in os.listdir(path):
 remote:        FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_c0914e5498ba1b53e00fb3adb7ce14d8/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
 remote: 
 remote:        https://devcenter.heroku.com/articles/django-assets
 remote:  !     Push rejected, failed to compile Python app.
 remote: 
 remote:  !     Push failed
 remote: Verifying deploy...
 remote: 
 remote: !  Push rejected to primedminds.
 remote: 
 To https://git.heroku.com/primedminds.git
  ! [remote rejected] master -> master (pre-receive hook declined)
 error: failed to push some refs to 'https://git.heroku.com/primedminds.git'
更新2:结果表明,它没有保存到AWS的至少一个原因是它想使用WhiteNoise本地文件存储(
WhiteNoise.storage.CompressedManifestStaticFilesStorage
),而不是我在设置文件中设置的AWS存储中间件:

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage’
罪魁祸首是设置文件末尾的这一行:

django_heroku.settings(locals())
该行覆盖我的
STATICFILES\u存储
变量。所以我把它改成:

django_heroku.settings(locals(), staticfiles=False)
我原以为这会解决问题,但collectstatic仍然没有将我的
STATICFILES\u DIRS
中的文件放在我的AWS S3存储桶中。我在Heroku服务器上运行了以下命令:

django-admin collectstatic --settings=primedminds.settings
并得到以下输出:

~ $ django-admin collectstatic  --settings=primedminds.settings
/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

0 static files copied, 148 unmodified.
~$django admin collectstatic--settings=primedminds.settings
/app/.heroku/python/lib/python3.6/site packages/psycopg2/_init__u;.py:144:UserWarning:psycopg2控制盘包将从2.8版重命名;为了保持从二进制文件安装,请改用“pip安装psycopg2二进制文件”。有关详细信息,请参阅:。
""")
您已请求在目标位置收集静态文件
在设置中指定的位置。
这将覆盖现有文件!
你确定要这样做吗?
键入“是”继续,或键入“否”取消:是
已复制0个静态文件,未修改148个。
至少现在它不只是在本地复制文件。但仍然没有文件复制到AWS。我也用
--清除
标志尝试了它,但没有骰子

[顺便说一句,我不得不使用
django admin
命令,而不是
python manage.py collectstatic
,因为后一个命令由于某种原因没有生成项目设置文件!]

这已经太久了,我可能只是在这一点上和自己说话,但我现在面临的问题是,为什么collectstatic没有像我预期的那样运行,将我的
STATICFILES\u DIRS
中的文件放入我的AWS S3存储桶

django_heroku.settings(locals(), staticfiles=False)
django-admin collectstatic --settings=primedminds.settings
~ $ django-admin collectstatic  --settings=primedminds.settings
/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

0 static files copied, 148 unmodified.