【发布时间】:2023-01-27 04:31:06
【问题描述】:
我有一个 django 项目,我已设法将其部署到弹性 beanstalk 服务器,但过去两天一直在尝试创建超级用户但无济于事。我遵循了该站点的不同指南和答案,但是对于我的一生,我就是无法使它正常工作。
我在本地执行此操作没有问题,其他容器命令即迁移在通过 .ebextensions/django.config 部署时工作正常,但是当我添加 create_superuser 容器命令时它失败了。请查看我的项目的以下树结构以及用于运行此步骤的相关文件:
wfi_workflow.ebextensions\django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: wfi_workflow.wsgi:application
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "wfi_workflow.settings.prod"
aws:elasticbeanstalk:environment:proxy:staticfiles:
"/static": "static/"
packages:
yum:
python3-devel: []
mariadb-devel: []
container_commands:
01_collectstatic:
command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput"
02_migrate:
command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate --noinput"
leader_only: true
03_create_superuser:
command: "source /var/app/venv/*/bin/activate && python3 manage.py mysuperuser"
leader_only: true
wfi_workflow\apps\account\management\commands\mysuperuser.py
import os
from django.core.management.base import BaseCommand
from apps.account.models import User
class Command(BaseCommand):
def handle(self, *args, **options):
if not User.objects.filter(username='test').exists():
User.objects.create_superuser('test',
'test@tesst.com',
'test1234')
如果有人可以帮助我解决这个问题或者我遗漏了什么,我将不胜感激。谢谢
【问题讨论】:
标签: python django amazon-web-services amazon-elastic-beanstalk