【发布时间】:2020-04-13 22:37:51
【问题描述】:
我只是想创建一个超级用户,以便我可以登录到我网站的管理部分。到目前为止,其他一切都在工作。 这是我的活动错误日志的相关部分:
[2019-12-22T05:02:06.721Z] INFO [26175] - [Application update app-191222_070106@18/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_ss_app/Test for Command 02_createsuperuser] : Starting activity...
[2019-12-22T05:02:06.725Z] INFO [26175] - [Application update app-191222_070106@18/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_ss_app/Test for Command 02_createsuperuser] : Completed activity. Result:
Completed successfully.
[2019-12-22T05:02:06.726Z] INFO [26175] - [Application update app-191222_070106@18/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_ss_app/Command 02_createsuperuser] : Starting activity...
[2019-12-22T05:02:07.074Z] INFO [26175] - [Application update app-191222_070106@18/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_ss_app/Command 02_createsuperuser] : Activity execution failed, because: Traceback (most recent call last):
File "/opt/python/current/app/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/commands/shell.py", line 92, in handle
exec(sys.stdin.read())
File "<string>", line 1
from users.models import UserProfile; UserProfile.objects.create_superuser(xxxxxxx@gmail.com', 'passxxxword')
^
SyntaxError: invalid syntax
(ElasticBeanstalk::ExternalInvocationError)[2019-12-22T05:02:06.721Z] INFO [26175] - [Application update app-191222_070106@18/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_ss_app/Test for Command 02_createsuperuser] : Starting activity...
[2019-12-22T05:02:06.725Z] INFO [26175] - [Application update app-191222_070106@18/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_ss_app/Test for Command 02_createsuperuser] : Completed activity. Result:
Completed successfully.
[2019-12-22T05:02:06.726Z] INFO [26175] - [Application update app-191222_070106@18/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_ss_app/Command 02_createsuperuser] : Starting activity...
[2019-12-22T05:02:07.074Z] INFO [26175] - [Application update app-191222_070106@18/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_ss_app/Command 02_createsuperuser] : Activity execution failed, because: Traceback (most recent call last):
File "/opt/python/current/app/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/management/commands/shell.py", line 92, in handle
exec(sys.stdin.read())
File "<string>", line 1
from users.models import UserProfile; UserProfile.objects.create_superuser(xxxxxxx@gmail.com', 'passxxxword')
^
SyntaxError: invalid syntax
(ElasticBeanstalk::ExternalInvocationError)
我正在尝试通过 db-migrate.config 文件进行部署:
container_commands:
01_migrate:
command: "django-admin.py migrate"
leader_only: true
02_createsuperuser:
command: "echo \"from users.models import UserProfile; UserProfile.objects.create_superuser(xxxxxxx@gmail.com', 'passxxxword')\" | /opt/python/run/venv/bin/python /opt/python/current/app/manage.py shell"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: studyspot.settings
【问题讨论】:
-
您尝试通过
shell管理命令而不是createsuperuser管理命令执行此操作是否有特殊原因? -
这是一个自定义用户模型,我不知道还有其他方法,因为它确实需要在 manager.py 中实现 create_superuser
-
只要设置了
DJANGO_SETTINGS_MODULE和settings.AUTH_USER_MODEL,使用createsuperuser应该没问题。 -
django 用户模型的重点不是让所有用户,包括同一个用户表中的超级用户吗?
-
没有关注?只要设置正确,
createsuperuser应该在您的自定义用户表中创建用户。
标签: django amazon-elastic-beanstalk