我尝试将我的应用程序部署到Railway.app。应用程序通常可以工作,但静态文件是找不到的。按照部署教程中的建议,我使用命令django manage.py collectstatic创建了集合静态文件夹,但没有帮助。有什么线索可能会出错吗?
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')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发布于 2022-09-26 02:54:23
WhiteNoise为我工作:
pip install whitenoise在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"发布于 2022-09-23 12:18:15
我也有类似的问题,我认为这是一件与铁路应用程序有关的事情,我最终使用Cloudinary存储我的静态文件
pip install django-cloudinary-storage一旦您这样做,添加cloudinary和cloudinary_storage到您安装的应用程序在您的settings.py。如果要将此包用于静态和/或媒体文件,请确保cloudinary_storage位于django.contrib.staticfiles之前:
INSTALLED_APPS = [
# ...
'cloudinary_storage',
'django.contrib.staticfiles',
'cloudinary',
# ...
]接下来,您需要向settings.py添加Cloudinary凭据:
CLOUDINARY_STORAGE = {
'CLOUD_NAME': 'your_cloud_name',
'API_KEY': 'your_api_key',
'API_SECRET': 'your_api_secret'
}那就跑
python manage.py collectstatic --noinputhttps://stackoverflow.com/questions/73825257
复制相似问题