python - Heroku django "OSError: [Errno 2] No such file or directory: '/static/static'"

标签 python django git heroku

我是 django 和 heroku 的新手。这是我将 git 存储库部署到 heroku 时遇到的错误。请建议我需要更改的更改。预先感谢您

(网站)C:\Users\website\src>heroku run python manage.pycollectstatic --无输入 运行python manage.py collectstatic --noinput连接到终端...启动,运行。1690

  Traceback (most recent call last):
  File "manage.py", line 10, in <module>
   execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__
.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__
.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py"
, line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py"
, line 338, in execute
output = self.handle(*args, **options)
 File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py"
, line 533, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
collected = self.collect()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 111, in list
for path in utils.get_files(storage, ignore_patterns):
 File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 27, in get_files
directories, files = storage.listdir(location)
 File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py",
line 270, in listdir
for entry in os.listdir(path):
 OSError: [Errno 2] No such file or directory: '/static/static'

设置.py

   STATIC_URL = '/static/'

  # Template location

 TEMPLATE_DIRS = (
      os.path.join(os.path.dirname(BASE_DIR), "static", "templates" ),

    )


if DEBUG:
    MEDIA_URL = '/media/'
    STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static",  "static-only" )
    MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "media" )
    STATICFILES_DIRS = (
       os.path.join(os.path.dirname(BASE_DIR), "static", "static" ),

   )

最佳答案

如果您已按如下方式声明“STATICFILES_DIRS”变量,

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

确保:

  1. 存在静态文件夹(该文件夹必须按照您在“STATICFILES_DIRS”变量中指定的名称命名)。
  2. 它包含一个文件。如果您还没有文件,可以将虚拟文件命名为“.any”。

关于python - Heroku django "OSError: [Errno 2] No such file or directory: '/static/static'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29082028/

相关文章:

python - 遍历嵌套的字符串列表以获取第一项

python - 如何将 scipy.stats.describe 应用于每个组?

python - 呈现形式 ('utf-8' 中的 Django UnicodeEncodeError )

python - Django models.py 循环外键

python - 来自嵌套字典的 Pandas 数据框将 dict 键添加到自己的列

python - 使 Tkinter 组合框滚动条和箭头按钮更大

DJANGO:mixins.DestroyModelMixin 删除 - 方法不允许

git - 如何将特定文件从 Azure Repos 复制到 unix 计算机

php - 在 CentOS 上为 Apache 用户创建 SSH key

git - 如何使用 Node.js 获取远程 git 分支?