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'`

and my settings.py looks like this

    # 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/"

so where could the trouble be? Ready to add more resources on request Thanks in advance

Jet Ezra
  • 164
  • 2
  • 9
  • am sorry if the question is not well clear but i can further explain on request – Jet Ezra Jun 24 '20 at 02:06
  • You are already having problem executing the script locally or you hardcoded your local paths. `/home/jet` isn't a path provided by Heroku. – Tin Nguyen Jun 24 '20 at 07:04
  • The issue is still local, and when I try on heroku it becomes worse – Jet Ezra Aug 05 '20 at 16:37
  • If you tag something with Heroku the expectance is that it is working locally. `FileNotFoundError: [Errno 2] No such file or directory: '/home/jet/myapp/static'` Verify it exists and verify your program has sufficient rights to read the directory. – Tin Nguyen Aug 06 '20 at 06:46

1 Answers1

0

The reason for this error is that you are using references to some files which do not exist in your project's static folder. You would either need to delete those references or create dummy files (in case they are not important) for the collectstatic to execute successfully. Also in this case I think you would need to register your static files in the URLs and in case you have already done that then make sure that there exists a directory called myapp in that registered base static directory.
You should try running the command python manage.py collectstatic locally before again pushing to heroku. Another workaround could be disabling the collectstatic usingheroku config:set DISABLE_COLLECTSTATIC=1 although that is not the correct way to do it
Refer: Collectstatic error while deploying Django app to Heroku for more details

Amartya Gaur
  • 665
  • 6
  • 21