AWS ElasticBeanstalk 如何使用 django 上传静态文件

AWS ElasticBeanstalk how to upload staticfiles with django

我尝试上传静态文件:

aws:elasticbeanstalk:环境:代理:静态文件: /静态:/静态

中遇到了这个错误
2022-04-27 03:34:07    ERROR   "option_settings" in one of the configuration files failed validation. More details to follow.
2022-04-27 03:34:07    ERROR   Invalid option specification (Namespace: 'aws:elasticbeanstalk:enviroment:proxy:staticfiles', OptionName: '/static'): Unknown configuration setting.
2022-04-27 03:34:07    ERROR   Failed to deploy application.

ERROR: ServiceError - Failed to deploy application.

我也试过只做

python manage.py collectstatic

它没有用

我以这种方式尝试了我的settings.py:

STATIC_URL = '/static/'
STATIC_ROOT = 'static'

和这种方式(我目前使用的方式):

STATIC_URL = '/static/'
STATIC_ROOT = 'static'
STATICFILES_DIRS = [BASE_DIR / 'templates/static']

您可以尝试以下适合我的配置。

settings.py

DEBUG = False
STATIC_URL = '/static/'
STATIC_ROOT = 'static'

运行 python manage.py collect static

转到根 urls.py 并添加

from django.conf.urls import url
from django.conf import settings
from django.views.static import serve 

urlpatterns = [
    ...
    ...
    url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}), 
]

可以参考Github