我试图在 heroku 上部署我的 django 应用程序,我没有创建虚拟环境,这是我第一次这样做。当我尝试推送到 heroku 时,在安装所有软件包后出现错误 -:
-----> $ 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
我不知道该怎么做,我是 Heroku 和 git 的新手。
这就是我的目录的外观,感谢您的帮助。
答案 0 :(得分:1)
我认为您没有在设置中添加 static_root...
让我帮你, 确保您已将其添加到您的项目 urls.py 文件中
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)
& 在您的 settings.py 中,您必须添加此内容,因此 collect static 将加载您为此域的静态文件。 例如
STATIC_URL = '/static/'
STATIC_ROOT = "/var/www/example.com/static/"
然后尝试运行 collect static 命令
如果您想了解有关此静态文件的更多信息,可以查看此文档:
https://docs.djangoproject.com/en/3.1/howto/static-files/
https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-STATIC_ROOT