问题描述
我正在使用django-tenant-schema(和PostgreSQL)开发多租户应用程序。现在,一旦创建了新的架构,我就使用call_command创建一个超级用户。我还想到了使用信号post_migrate的选项。
I'm working on a multi tenant app using django-tenant-schema(and postgresql). Now as soon as the new schema is getting created, I'm using the call_command to create a superuser. I also thought of the option of using signal post_migrate.
我的疑问是,如何在不输入密码的情况下自动创建超级用户。
用例是在用户注册其架构后立即生成一个超级用户,并使用该超级用户的用户名和密码登录,然后可以更改密码。
My doubt is how can I auto create a superuser without typing the password in shell.The use case is as soon as the user registers for his/her schema, a superuser is generated and the user logs in with the superuser username and password and can change the password thereafter.
我正在使用以下命令来调用createsuperuser命令:
I'm using the following to call the createsuperuser command:
call_command('createsuperuser', schema_name=self.schema_name, username='admin', email='admin@admin.com')
解决该问题的一种方法是更改Django的 createsuperuser.py
文件,并在该文件中自动提供密码,但这多数民众赞成,这是不可接受的途径,例如,对源代码进行一些使用案件。我可以要求一些更好的方法吗?
One way to solve the issue is to change Django's createsuperuser.py
file and provide a password over there automatically, buts thats not an acceptable route, ie cahnging the source code for some use case. Could I please request for some better methods
推荐答案
您可以为新的超级用户准备密码并将md5值传递给bash:
you can "prepare" password for new superuser and pass md5 value to bash:
a=# select md5('some password'||'test');;
md5
----------------------------------
d5b3eb515b64edf295b2ee9062946d24
(1 row)
a=# create user test superuser password 'md5d5b3eb515b64edf295b2ee9062946d24';
CREATE ROLE
因此您可以使用 d5b3eb515b64edf295b2ee9062946d24
在bash中,在其他地方保存密码了吗?。
so you can use d5b3eb515b64edf295b2ee9062946d24
in bash, saving password somewhere else?..
这篇关于使用每个架构Django自动创建超级用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!