Deploy static assets to heroku from local machine - can't open file 'manage.py': [Errno 2] No such file or directory

前端 未结 2 1427
时光取名叫无心
时光取名叫无心 2021-01-14 06:21

I am trying deploy my assets files to heroku and I get this output in my command line interface:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ her         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 06:52

    Have you properly defined:

    STATICFILES_DIRS
    

    Inside your settings.py?

    Have you created it locally and added it to git (as empty directory...). The trace you have indicates that this folder is missing. I have created a simple project with the following settings:

    ~/Software/h/hrku $ tail hrku/settings.py 
    USE_TZ = True
    
    
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/1.9/howto/static-files/
    
    STATIC_URL = '/static/'
    
    STATIC_ROOT = '/var/www/dj'
    STATICFILES_DIRS = (os.path.join(os.path.dirname(__file__), '..', 'static'),)
    

    As you can see the STATICFILES_DIRS contains only one directory, which does not exist:

    ~/Software/h/hrku $ ls -l /home/ozn/Software/h/hrku/static
    ls: cannot access /home/ozn/Software/h/hrku/static: No such file or directory
    

    The command collectstatic fails:

    ~/Software/h/hrku $ python manage.py collectstatic
    
    You have requested to collect static files at the destination
    location as specified in your settings:
    
        /var/www/dj
    
    This will overwrite existing files!
    Are you sure you want to do this?
    
    Type 'yes' to continue, or 'no' to cancel: yes
    Traceback (most recent call last):
      File "manage.py", line 10, in 
        execute_from_command_line(sys.argv)
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
        utility.execute()
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
        self.execute(*args, **cmd_options)
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
        output = self.handle(*args, **options)
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
        collected = self.collect()
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
        for path, storage in finder.list(self.ignore_patterns):
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
        for path in utils.get_files(storage, ignore_patterns):
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
        directories, files = storage.listdir(location)
      File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/files/storage.py", line 299, in listdir
        for entry in os.listdir(path):
    FileNotFoundError: [Errno 2] No such file or directory: '/home/ozn/Software/h/hrku/static'
    

    I hope this will lead you to solving your problem.

提交回复
热议问题