Search code examples
pythondjangoheroku

Heroku try to deploy python website ,,manage.py collestatic --noninput"


I create a website using Python ,JS, React, Django .When I deployed on Heroku via github, an error occur:

-----> Determining which buildpack to use for this app
!     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
          Detected buildpacks: Python,Node.js
          See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Python app detected
-----> Using Python version specified in Pipfile.lock
cp: cannot stat '/tmp/build_02d1f320/requirements.txt': No such file or directory
-----> Installing python-3.9.7
-----> Installing pip 20.2.4, setuptools 57.5.0 and wheel 0.37.0
-----> Installing dependencies with Pipenv 2020.11.15
     Installing dependencies from Pipfile.lock (dee4f1)...
-----> Installing SQLite3
-----> $ python leadmanager/manage.py collectstatic --noinput
     Traceback (most recent call last):
       File "/tmp/build_02d1f320/leadmanager/manage.py", line 22, in <module>
         main()
       File "/tmp/build_02d1f320/leadmanager/manage.py", line 18, in main
         execute_from_command_line(sys.argv)
       File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
         utility.execute()
       File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
         self.fetch_command(subcommand).run_from_argv(self.argv)
       File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
         self.execute(*args, **cmd_options)
       File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
         output = self.handle(*args, **options)
       File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
         collected = self.collect()
       File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
         handler(path, prefixed_path, storage)
       File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 338, in copy_file
         if not self.delete_file(path, prefixed_path, source_storage):
       File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 248, in delete_file
         if self.storage.exists(prefixed_path):
       File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py", line 318, in exists
         return os.path.exists(self.path(name))
       File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 38, in path
         raise ImproperlyConfigured("You're using the staticfiles app "
     django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
!     Error while running '$ python leadmanager/manage.py collectstatic --noinput'.
     See traceback above for details.
     You may need to update application code to resolve this error.
     Or, you can disable collectstatic for this application:
        $ heroku config:set DISABLE_COLLECTSTATIC=1
     https://devcenter.heroku.com/articles/django-assets
!     Push rejected, failed to compile Python app.
!     Push failed 

Here is my github repository:enter link description here

When I try to run my website via localhost:8000 , it work well , but now , when I tryed to deploy on Heroku , this error occur. My db is build using django. Please help me ,thx!!


Solution

  • From the error traceback STATIC_ROOT url isn't configured.

    You need to configure the static files dir url at your django app settings.py script for example as follows: STATIC_ROOT = BASE_DIR + "../your-static-dir"

    After that you can add run the collect static command on Heroku heroku run python manage.py collectstatic --dry-run --noinput

    Also consider checking this question's statement for more info about configuring your static & media urls. Django 301 and 403 forbidden errors on my static files in production