![](/img/trans.png)
[英]linux shell script: how can I create a service that will run in background?
[英]How to create a superuser in Django with Linux shell script?
最近,我想用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.
但是當使用docker部署應用程序時,我必須在腳本中編寫此命令,該腳本將在docker容器啟動后執行。如何在腳本中設置用戶名,電子郵件和密碼? 謝謝!
#!/bin/bash
python manage.py createsuperuser
您可以提供夾具,而不是使用createsuperuser
管理命令。
您需要為auth.user
模型提供一個fixture。 對於密碼,您可以通過Django shell生成一個密碼
>>> from django.contrib.auth.hashers import make_password
>>> make_password('password')
您的最終夾具應如下所示:
[
{ "model": "auth.user",
"pk": 1,
"fields": {
"username": "admin",
"password": "<output of make_password()>"
"is_superuser": true,
"is_staff": true,
"is_active": true
}
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.