Reputation: 1489
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.
This is how my directory looks, any help is appreciated.
Upvotes: 0
Views: 400
Reputation: 172
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
Upvotes: 1