您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Django上自动化createsuperuser?

如何在Django上自动化createsuperuser?

如果直接引用用户,则您的代码将无法在AUTH_USER_MODEL设置更改为其他用户模型的项目中使用。创建用户的更通用的方法是:

echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@myproject.com', 'password')" | python manage.py shell

原始答案

这里是创建超级用户的脚本的简单版本:

echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'pass')" | python manage.py shell
Go 2022/1/1 18:23:41 有308人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶