Django elastic beanstalk未创建超级用户,语法无效
我只是想创建一个超级用户,这样我就可以登录到我的网站的管理部分。到目前为止,其他一切都在发挥作用。 以下是我的活动错误日志的相关部分:Django elastic beanstalk未创建超级用户,语法无效,django,amazon-elastic-beanstalk,Django,Amazon Elastic Beanstalk,我只是想创建一个超级用户,这样我就可以登录到我的网站的管理部分。到目前为止,其他一切都在发挥作用。 以下是我的活动错误日志的相关部分: [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 0
[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)
Elastic beanstalk最终在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
02_createsuperuser:
command: "echo \"from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('xxxxx@gmail.com', 'xxxxxpasword')\" | python manage.py shell"
这是一个自定义的用户模型,目前还没有太多关于它的信息,所以我希望这对其他人有所帮助。我没有在这里包含managers.py文件,但是这部分应该很简单,而且我必须确保在forms.py文件的用户创建表单中有一个save user函数。我花了一周的时间才弄明白,所以我将其发布以帮助他人。Elastic beanstalk最终在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
02_createsuperuser:
command: "echo \"from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('xxxxx@gmail.com', 'xxxxxpasword')\" | python manage.py shell"
这是一个自定义的用户模型,目前还没有太多关于它的信息,所以我希望这对其他人有所帮助。我没有在这里包含managers.py文件,但是这部分应该很简单,而且我必须确保在forms.py文件的用户创建表单中有一个save user函数。我花了一周的时间才弄明白,所以我将其发布以帮助他人。您是否有特殊原因试图通过
shell
管理命令而不是createsuperuser
管理命令来执行此操作?这是一个自定义用户模型,我不知道还有其他方法,因为它确实需要在管理器中实现create_superuser。py只要DJANGO_设置_模块
和设置。设置了AUTH_用户模型
,您就可以使用createsuperuser
。DJANGO用户模型的目的不是要拥有所有用户,是否将超级用户包含在同一用户表中?是否不遵循<只要设置正确,code>createsuperuser应该在自定义用户表中创建用户。您试图通过shell
管理命令而不是createsuperuser
管理命令来创建用户,这是一种自定义用户模型,我不知道还有其他方法,因为它确实需要在管理器中实现create_superuser。py只要DJANGO_设置_模块
和设置。设置了AUTH_用户模型
,您就可以使用createsuperuser
。DJANGO用户模型的目的不是要拥有所有用户,是否将超级用户包含在同一用户表中?是否不遵循<只要设置正确,code>createsuperuser应该在自定义用户表中创建用户。