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

Alg*_*bra 4 python django heroku

collectstatic用命令禁用

\n\n
heroku config:set DISABLE_COLLECTSTATIC=1\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n
$ heroku run python manage.py collectstatic\n
Run Code Online (Sandbox Code Playgroud)\n\n

不幸的是,Heroku 报告错误涉及manage.py

\n\n
Running python manage.py collectstatic on \xe2\xac\xa2 fierce-cove-94300... up, run.6296 (Free)\n/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>.\n  """)\nTraceback (most recent call last):\n  File "manage.py", line 22, in <module>\n    execute_from_command_line(sys.argv)\n  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line\n    utility.execute()\n  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute\n    self.fetch_command(subcommand).run_from_argv(self.argv)\n  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv\n    self.execute(*args, **cmd_options)\n  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute\n    output = self.handle(*args, **options)\n  File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 173, in handle\n    if self.is_local_storage() and self.storage.location:\n  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 239, in inner\n    return func(self._wrapped, *args)\n  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__\n    res = instance.__dict__[self.name] = self.func(instance)\n  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 283, in location\n    return abspathu(self.base_location)\n  File "/app/.heroku/python/lib/python3.6/posixpath.py", line 371, in abspath\n    path = os.fspath(path)\nTypeError: expected str, bytes or os.PathLike object, not tuple\n
Run Code Online (Sandbox Code Playgroud)\n\n

设置.py

\n\n
#Heroku Setting\ncwd = os.getcwd()\nif cwd == "/app" or cwd[:4] == "/tmp":\n    import dj_database_url\n    DATABASES = { #DATABASES plurual\n        "default": dj_database_url.config(default="postgres://localhost"),\n    }\n\n    #Honor the "X-Forwarded-Proto" header for request.is_secure().\n    SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", \'https\')\n\n    # Allow all host headers\n    ALLOWED_HOSTS = [\'*\']\n\n    #Static asset configuration\n    BASE_DIR = os.path.dirname(os.path.abspath(__file__))\n    STATIC_ROOT = (BASE_DIR, "staticfiles")\n    STATICFILES_DIRS = (\n        os.path.join(BASE_DIR, \'static\'),\n    )\n
Run Code Online (Sandbox Code Playgroud)\n\n

遇到这样的问题怎么解决呢?

\n

Sel*_*cuk 5

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

STATIC_ROOT = (BASE_DIR, "staticfiles")
Run Code Online (Sandbox Code Playgroud)

将其更改为:

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
Run Code Online (Sandbox Code Playgroud)