在 vercel 中上传 Django 项目时不断出现错误

问题描述 投票:0回答:1

当我使用 Vercel 部署 Django 项目时,我不断收到此错误

Error: No Output Directory named "staticfiles_build" found after the Build completed. You can configure the Output Directory in your Project Settings

我尝试了很多方法来解决该错误,但没有任何效果。 这是我的setting.py代码

# Static files (CSS, JavaScript, Images)

# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
   os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_build', 'static')

我想在 Vercel 的帮助下在线部署我的项目,但我不断收到错误

django error-handling deployment vercel
1个回答
0
投票

这是我的配置(“settings.py”和“vercel.json”),对我有用:

// settings.py
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticfiles" / "static"
STATICFILES_DIRS = [BASE_DIR / "static"]

// vercel.json
{
  "regions": ["sin1"],
  "version": 2,
  "builds": [
    {
      "src": "configs/wsgi.py",
      "use": "@vercel/python",
      "config": { "maxLambdaSize": "15mb", "runtime": "python3.9" }
    },
    {
      "src": "vercel_build.sh",
      "use": "@vercel/static-build",
      "config": {
        "distDir": "staticfiles"
      }
    }
  ],
  "routes": [
    {
      "src": "/static/(.*)",
      "dest": "/static/$1"
    },
    {
      "src": "/(.*)",
      "dest": "configs/wsgi.py"
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.