0
`python manage.py collectstatic Traceback (most recent call last):   File "manage.py", line 21, in <module>
    main()   File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
    collected = self.collect()   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 104, in collect
    for path, storage in finder.list(self.ignore_patterns):   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/contrib/staticfiles/finders.py", line 130, in list
    for path in utils.get_files(storage, ignore_patterns):   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
    directories, files = storage.listdir(location)   File "/home/jet/venvfordjango/lib/python3.7/site-packages/django/core/files/storage.py", line 316, in listdir
    for entry in os.scandir(path): FileNotFoundError: [Errno 2] No such file or directory: '/home/jet/myapp/static'`

我的 settings.py 看起来像这样

    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))  
    
    .......
    
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/1.9/howto/static-files/
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    STATIC_URL = '/static/'
    
    # Extra places for collectstatic to find static files.
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),
    )
    ........

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

那么问题出在哪里呢?准备根据要求添加更多资源提前致谢

4

1 回答 1

0

此错误的原因是您正在使用对项目静态文件夹中不存在的某些文件的引用。您需要删除这些引用或创建虚拟文件(以防它们不重要)以使 collectstatic 成功执行。同样在这种情况下,我认为您需要在 URL 中注册静态文件,如果您已经这样做了,请确保在该注册的基本静态目录中存在一个名为 myapp 的目录。
在再次推送到 heroku 之前,您应该尝试在本地运行命令 python manage.py collectstatic。另一种解决方法可能是禁用 collectstatic usingheroku config:set DISABLE_COLLECTSTATIC=1虽然这不是正确的方法
参考:Collectstatic error while deploying Django app to Heroku更多细节

于 2020-06-24T06:38:43.750 回答