我使用命令
禁用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'),
)
如何解决这样的问题?
答案 0 :(得分:2)
错误在model.fit()
设置中。正如错误消息所述,您传递的是元组而不是路径:
STATIC_ROOT
将其更改为:
STATIC_ROOT = (BASE_DIR, "staticfiles")