我的應用程序正常運行在我的本地,我可以運行沒有錯誤Heroku的錯誤使用收集靜態和Django 1.10
。但是當在構建過程結束時推送到Heroku時,出現以下錯誤:
$ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
collected = self.collect()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 115, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py", line 399, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/tmp/build_732715d9b29ba88f9eb56ca3d7e722de/MY_REAL_APP_NAME/static'
因此我的構建被拒絕。我查看了OSError: [Errno 2] No such file or directory: '/tmp/MakeCalls/Static',但是當我刪除我的STATICFILES_DIRS
時,該應用會部署,但所有靜態資產都會收到404錯誤。我正在按照Heroku exactly上的說明進行操作,但似乎不起作用。我settings.py
文件的相關部分如下:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
ALLOWED_HOSTS = ['*']
和我wsgi.py
文件:
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fortuno.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
這一切似乎都在我的本地工作正常,當我運行heroku local web
。任何想法可能會導致收集靜態錯誤?
你打造的「靜態」文件夾在Django項目文件夾裏面?如果沒有,請創建一個空文件。看看Heroku文檔中的示例存儲庫以及這個空的[file]的路徑(https://github.com/heroku/python-getting-started/tree/master/gettingstarted/static) –
是的,我有它。它充滿了我的引導文件和圖像。 – jjones2000
你可以顯示你的項目目錄結構嗎? –