Railway.app 部署 django 应用程序后找不到静态文件

use*_*381 1 django django-staticfiles

我尝试将我的应用程序部署到 Railway.app。应用程序通常可以运行,但找不到静态文件。我已django manage.py collectstatic按照部署教程中的建议使用命令创建了collectstatic 文件夹,但它没有帮助。任何线索可能出了什么问题吗?

设置.py

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Run Code Online (Sandbox Code Playgroud)

staticfiles 文件夹位于包含 menage.py 文件的目录中

从railway.apps 部署日志

Not Found: /staticfiles/style.css
Not Found: /staticfiles/base.css
Not Found: /staticfiles/MyImage.png
Not Found: /staticfiles/base.js
Run Code Online (Sandbox Code Playgroud)

小智 13

WhiteNoise 对我有用:

pip install whitenoise
Run Code Online (Sandbox Code Playgroud)

在你的 settigs.py 中:

INSTALLED_APPS = [
    'django.contrib.staticfiles',
    'whitenoise.runserver_nostatic',    
]

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "whitenoise.middleware.WhiteNoiseMiddleware",
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE="whitenoise.storage.CompressedManifestStaticFilesStorage"
Run Code Online (Sandbox Code Playgroud)