在AWS弹性魔豆创建Django的超级用户 [英] Create Django Superuser on AWS Elastic Beanstalk

查看:274
本文介绍了在AWS弹性魔豆创建Django的超级用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为MYUSER一个自定义的用户类。它的工作原理局部精细与注册,登录等。我试图部署我的应用程序AWS弹性魔豆,我遇到了一些问题,创造我的超级用户。

I have a custom user class called MyUser. It works fine locally with registrations, logins and so on. I'm trying to deploy my application to AWS Elastic Beanstalk and I'm running into some problems with creating my superuser.

我试图使一个脚本文件并运行它作为官方 AWS指南建议。没有工作好,所以我决定尝试一种辅助方法的这里提出并创建自定义manage.py命令来创建我的用户。

I tried making a script file and run it as the official AWS guide suggests. Didnt work well so I decided to try a secondary method suggested here and create a custom manage.py command to create my user.

当我部署我在日志中得到以下错误。

When I deploy I get the following errors in the log.

[Instance: i-8a0a6d6e Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] command failed with error code 1: Error occurred during build: Command 02_createsu failed.

[2015-03-10T08:05:20.464Z] INFO  [17937] : Command processor returning results: 
{"status":"FAILURE","api_version":"1.0","truncated":"false","results":[{"status":"FAILURE","msg":"[CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] command failed with error code 1: Error occurred during build: Command 02_createsu failed","returncode":1,"events":[]}]}


[2015-03-10T08:05:20.463Z] ERROR [17937] : Command execution failed: [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] command failed with error code 1: Error occurred during build: Command 02_createsu failed (ElasticBeanstalk::ActivityFatalError)
at /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:189:in `rescue in exec'
...
caused by: command failed with error code 1: Error occurred during build: Command 02_createsu failed (Executor::NonZeroExitStatus)

在code如下所示:

The code looks like the following:

这是在.ebextensions我mysite.config文件/

This is my mysite.config file in .ebextensions/

01_syncdb 03_collectstatic 工作正常。

container_commands:
  01_syncdb:    
    command: "django-admin.py migrate --noinput"
    leader_only: true
  02_createsu:
    command: "manage.py createsu"
    leader_only: true
  03_collectstatic:
    command: "django-admin.py collectstatic --noinput"
option_settings:
  - namespace: aws:elasticbeanstalk:container:python
    option_name: WSGIPath
    value: treerating/wsgi.py
  - option_name: DJANGO_SETTINGS_MODULE
    value: treerating.settings

这是我的 /profiles/management/commands/createsu.py 文件:

from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from profiles.models import MyUser

class Command(BaseCommand):
    def handle(self, *args, **options):
        if MyUser.objects.count() == 0:
            MyUser.objects.create_superuser("admin", "treerating", "password")

和我有 __的init __。PY 文件均 /管理/ /命令/ 文件夹。

And I have __init__.py files in both /management/ and /commands/ folders.

我试过这个命令在本地命令行并能正常工作,并创建没有错误的用户。所以不应该是用命令本身或任何问题 MyUser.objects.create_superuser()

I tried this command locally from command line and it works fine and creates the user without errors. So there shouldnt be any issue with the command itself or the MyUser.objects.create_superuser().

编辑:我试图改变我的高清处理():函数只设置一个变量和我仍然得到同样的错误。因此它似乎是问题不相关的create_superuser功能或把手,但与使用manage.py更多的东西。

I tried changing my def handle(): function to only set a variable to True and I still get the same errors. So it seems like the problem is not related to the create_superuser function or the handle, but more something with using manage.py.

任何想法?

编辑2: 我试图通过SSH执行命令和失败。然后我跟着的说明这篇文章并设置Python路径中的手动:

EDIT 2: I tried executing the command by SSH and failed. I then followed the instructions in this post and set the Python Path's manually with:

源的/ opt /蟒蛇/运行/ venv /斌/启动源的/ opt /蟒蛇/电流/ ENV

我就能够成功创建我的用户。 官方AWS Django的部署指南中没有提到这事。但我猜你是想以某种方式设置你的Python路径在.config文件。我不知道究竟是如何做到这一点,所以如果有人还是要回答这个问题,我将测试它,接受它作为回答是否会解决部署错误。

I was then able to successfully create my user. The official AWS Django Deployment guide does not mention anything about this. But I guess you are suppose to set your Python Path's in the .config file somehow. I'm not sure exactly how to do this so if someone still want to answer that, I will test it and accept it as answer if that will solve the deployment errors.

推荐答案

这工作对我来说是只是去直接进入config.yml文件并更改WSGI路径有另一种选择。你可以用获得EB配置命令,只是下降50行左右,进行更改,逃避和保存。这仅仅是一个特定环境下的解决方案,但。

Another alternative that worked for me is to just go directly into the config.yml file and change the wsgi path there. You can get access with the eb config command and just go down 50 lines or so, make your changes, escape and save. This is only an environment-specific solution though.

这篇关于在AWS弹性魔豆创建Django的超级用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆