我在 AWS 上创建了一个基本的 Python Django 环境。我的项目是使用 生成的django-admin startproject michaelmalura
。我使用 添加了一个应用程序django-admin startapp blog
。
我发布项目后,eb deploy
前端一切正常。但后端没有显示任何样式。
设置.py
...
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog'
]
...
STATIC_ROOT = os.path.join(BASE_DIR, "..", "static")
STATIC_URL = '/static/'
django.config
container_commands:
01_migrate:
command: "python manage.py migrate --noinput"
leader_only: true
02_collectstatic:
command: "python manage.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:container:python:environment":
DJANGO_SETTINGS_MODULE: "michaelmalura.settings"
aws:elasticbeanstalk:container:python:
WSGIPath: "michaelmalura/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
管理错误
Failed to load resource: the server responded with a status of 404 (Not Found) http://michaelmalura.eu-central-1.elasticbeanstalk.com/static/admin/css/base.css
答案1
我终于找到了解决这个问题的方法。我从 STATIC_ROOT 中删除了 ..
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATIC_URL = '/static/'