xan*_*-ye 2 linux django shell docker
最近,我想用docker部署一个应用程序.我遇到了一个关于如何编写将在Linux上执行的启动脚本的问题.一个例子是作为研究员:
通常,我们创建这样的超级用户:
iMac:mysite yetongxue$ python manage.py createsuperuser
Username (leave blank to use 'yetongxue'): root
Email address: example@qq.com
Password:
Password (again):
Superuser created successfully.
Run Code Online (Sandbox Code Playgroud)
但是当使用docker部署应用程序时,我必须在脚本中编写此命令,该脚本将在docker容器启动后执行.如何在脚本中设置用户名,电子邮件和密码?谢谢!
#!/bin/bash
python manage.py createsuperuser
Run Code Online (Sandbox Code Playgroud)
小智 11
createsuperuser您可以提供一个夹具,而不是使用管理命令.
您需要为auth.user模型提供夹具.对于密码,您可以通过Django shell生成一个密码
>>> from django.contrib.auth.hashers import make_password
>>> make_password('password')
Run Code Online (Sandbox Code Playgroud)
您的最终夹具应如下所示:
[
{ "model": "auth.user",
"pk": 1,
"fields": {
"username": "admin",
"password": "<output of make_password()>"
"is_superuser": true,
"is_staff": true,
"is_active": true
}
}
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1849 次 |
| 最近记录: |