简体   繁体   English

无法在 heroku 上部署我的 django 项目

[英]Failed to deploy my django project on heroku

I was going to deploy my django project on heroku, but I meet the error, I really have no idea how to do, please help, thank you a lot for your checking and answer in advance!我打算在heroku上部署我的django项目,但是我遇到了错误,我真的不知道该怎么做,请帮助,非常感谢您提前检查和回答!

 -----> $ python manage.py collectstatic --noinput
       Traceback (most recent call last):
         File "manage.py", line 22, in <module>
           main()
         File "manage.py", line 18, in main
           execute_from_command_line(sys.argv)
         File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
           utility.execute()
         File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
           self.fetch_command(subcommand).run_from_argv(self.argv)
         File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
           self.execute(*args, **cmd_options)
         File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
           output = self.handle(*args, **options)
         File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 194, in handle
           collected = self.collect()
         File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 109, in collect
           for path, storage in finder.list(self.ignore_patterns):
         File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/staticfiles/finders.py", line 130, in list
           for path in utils.get_files(storage, ignore_patterns):
         File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
           directories, files = storage.listdir(location)
         File "/app/.heroku/python/lib/python3.7/site-packages/django/core/files/storage.py", line 316, in listdir
           for entry in os.scandir(path):
       FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_fa7f7ad1_/static'
 !     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

And here is my django project setting.py file: https://github.com/wkeiss/lonelyisland/blob/master/lonelyisland/settings.py这是我的 django 项目 setting.py 文件: https://github.com/wkeiss/lonelyisland/blob/master/lonelyisland/settings.py

Comment WhiteNoiseMiddleware and try this评论WhiteNoiseMiddleware并试试这个

STATIC_URL = '/static/'
STATICFILES_DIRS = (
   os.path.join(BASE_DIR, 'static'),
)
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

STATIC_ROOT = os.path.join(PROJECT_ROOT, "staticfiles")

Actually worked for me, you can check my setting files here实际上对我有用,你可以在这里查看我的设置文件

STATICFILES_DIRS should contain List not Tuple i think我认为 STATICFILES_DIRS 应该包含 List 而不是 Tuple

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)

so try to chage it like this所以试着像这样改变它

STATICFILES_DIRS = [
BASE_DIR / "static",
]

Your error is coming because你的错误来了,因为

STATIC_URL = '/posts/static/'

You have given the URL of the static under the post你在帖子下给了static的URL

But you didn't write that in static_dirs但是你没有在 static_dirs 中写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM