gpt4 book ai didi

python - 在 Heroku 上部署时,报 TypeError : expected str, bytes or os.PathLike object, not tuple

转载 作者:太空宇宙 更新时间:2023-11-03 15:45:11 27 4
gpt4 key购买 nike

我用命令禁用collectstatic

heroku config:set DISABLE_COLLECTSTATIC=1

成功将我的项目推送到 Heroku 后,手动 collectstatic 如下:

$ heroku run python manage.py collectstatic

不幸的是,Heroku 报告引用 manage.py

的错误
Running python manage.py collectstatic on ⬢ fierce-cove-94300... up, run.6296 (Free)
/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 173, in handle
if self.is_local_storage() and self.storage.location:
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 239, in inner
return func(self._wrapped, *args)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 283, in location
return abspathu(self.base_location)
File "/app/.heroku/python/lib/python3.6/posixpath.py", line 371, in abspath
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not tuple

settings.py

#Heroku Setting
cwd = os.getcwd()
if cwd == "/app" or cwd[:4] == "/tmp":
import dj_database_url
DATABASES = { #DATABASES plurual
"default": dj_database_url.config(default="postgres://localhost"),
}

#Honor the "X-Forwarded-Proto" header for request.is_secure().
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

#Static asset configuration
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = (BASE_DIR, "staticfiles")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)

如何解决这样的问题?

最佳答案

错误在您的 STATIC_ROOT 设置中。如错误消息所述,您传递的是元组而不是路径:

STATIC_ROOT = (BASE_DIR, "staticfiles")

将其更改为:

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

关于python - 在 Heroku 上部署时,报 TypeError : expected str, bytes or os.PathLike object, not tuple,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50381314/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com