【问题标题】:configuring django admin on elastic beanstalk在弹性 beantalk 上配置 django admin
【发布时间】:2019-03-01 18:34:15
【问题描述】:

我很难将 django 管理员配置为使用弹性 beanstalk。我尝试了一切,但仍然无法正常工作。 当我单击管理员或我的标志页面时,我收到服务器错误 (500)。 我在项目的根目录中创建了一个名为 management 的文件夹,在其中我创建了另一个名为 commands 的文件夹和一个名为 createsu.py 的文件,这里是 createsu.py 的内容 从 django.core.management.base 导入 BaseCommand,CommandError from django.contrib.auth.models 导入用户

类命令(BaseCommand):

def handle(self, *args, **options):
    if not User.objects.filter(username="admin").exists():
        User.objects.create_superuser("admin", "admin@admin.com", "admin")
        self.stdout.write(self.style.SUCCESS('Successfully created new super user'))

在我的 .config 文件中,我添加了类似代码

03_createsu: 命令:“python manage.py createsu” leader_only: true

在 eb 部署并刷新弹性 beanstalk 控制台后,当我尝试访问网页时,我仍然收到相同的错误。我所有的其他页面都在工作,除了我的管理页面和标志页面之外,静态文件工作正常,因为它们连接到管理员。我已经为此苦苦挣扎了一个星期。有人可以帮帮我吗?

【问题讨论】:

    标签: python django amazon-web-services


    【解决方案1】:
    #I fixed the issue.
    #First typo was I forgot to add SITE_ID = 1 in my settings.py because I am using #flatpages.
    #Second typo I didn't configure my static files correctly. I fixed it to this:
    
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    STATIC_URL = '/static/'
    
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'assets'),
    )
    
    #Lastly createsu.py should be in the app folder not project folder. 
    

    【讨论】:

      猜你喜欢
      • 2014-03-19
      • 1970-01-01
      • 2016-01-16
      • 2014-06-13
      • 2023-03-12
      • 2014-01-26
      • 2012-08-24
      • 2017-07-15
      相关资源
      最近更新 更多