如何在django上自动创建createuperuser? [英] How to automate createsuperuser on django?
本文介绍了如何在django上自动创建createuperuser?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 django
上自动运行 migrate.py createduperuser
,但是接缝没有办法设置一个默认密码。
I want to auto run migrate.py createsuperuser
on django
but it seams that there is no way of setting a default password.
我该如何得到这个?它必须独立于django数据库。
How can I get this? It has to be independent on the django database.
推荐答案
这里有一个简单版本的脚本来创建超级用户: / p>
Here there is a simple version of the script to create a superuser:
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin@example.com', 'admin', 'pass')" | python manage.py shell
编辑
如注释所示,以下命令删除并创建超级用户,因此该命令始终适用于每个构建:
As suggested in the comments, the following command deletes and creates the superuser so the command always works for every build:
echo "from django.contrib.auth.models import User; User.objects.filter(email='admin@example.com').delete(); User.objects.create_superuser('admin@example.com', 'admin', 'nimda')" | python manage.py shell
这篇关于如何在django上自动创建createuperuser?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文