django - 弹性豆茎没有创建超级用户,语法无效
问题描述
我只是想创建一个超级用户,以便我可以登录到我网站的管理部分。到目前为止,其他一切都在工作。这是我的活动错误日志的相关部分:
[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
解决方案
Elastic beanstalk 终于在 db-migrate.config 文件中使用了我的超级用户命令:
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"
这是使用自定义用户模型,目前没有太多信息,所以我希望这对某人有所帮助。我没有在此处包含 manager.py 文件,但那部分应该很简单,而且我确实必须确保在我的 forms.py 文件中的用户创建表单中具有保存用户功能。这花了我一周的时间才弄清楚,所以我将其发布以帮助其他人。
推荐阅读
- docker - 如何从 CoreOS 上 docker 映像中的快照恢复 etcd 集群?
- isabelle - 显式实例化关于 Sequents 的公理
- c++ - 将矩阵(opencv)的向量转换为c ++数组
- python - 如何组合来自银行账户的两个数据框
- docker - 手动安装后我可以在 docker 中保存吗?
- python - 删除列表中的所有特定单词
- python - Numpy - 从距离矩阵中提取唯一值
- google-cloud-platform - 无法打开 Google App Maker 示例
- java - 带有 JMenuItem 多次调用操作的 Apple 屏幕菜单栏
- android - 如何处理不同 android 版本 BLE 的监督超时?