0

I was trying to deploy my django app on heroku, I did not create a virtual environment, and this is my first time doing it. When I tried to push to heroku I got error after installing all packages -:

-----> $ python manage.py collectstatic --noinput
   Traceback (most recent call last):
     File "/tmp/build_b0d1f9a6/manage.py", line 22, in <module>
       main()
     File "/tmp/build_b0d1f9a6/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 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

I cannot understand what to do, I am new to heroku, git.

enter image description here

This is how my directory looks, any help is appreciated.

1 Answer 1

1

I think you didn't added static_root in your settings...

let me help you, make sure you have added this in your projects urls.py file

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

& In your settings.py you have to add this, so collect static will load your static files for this domain. for ex.

STATIC_URL = '/static/'
STATIC_ROOT = "/var/www/example.com/static/"

then try to run collect static command

if you want to learn more about this static files you can see this documents:

https://docs.djangoproject.com/en/3.1/howto/static-files/

https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-STATIC_ROOT

Sign up to request clarification or add additional context in comments.

2 Comments

So basically I need to upload my static file on any cloud storage, and give a link to that ?
no! you have to add these in your settings.py file then run the command: python manage.py collectstatic. Then it will work. i think the problem is that, heroku is not able to detect your static files so we have to give link of those static files. by doing static_root u will tell the heroku where to find those static files. you can learn about static files from the documentation. i have provided the links take a look at them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.