Python 无法使用 Django manage.py 创建超级用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32532900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Not able to create super user with Django manage.py
提问by gerosalesc
Trying to create a super user for my database:
试图为我的数据库创建一个超级用户:
manage.py createsuperuser
Getting a sad recursive message:
收到一条悲伤的递归消息:
Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser
in your project to create one manually.
由于不在 TTY 中运行,超级用户创建被跳过。您可以manage.py createsuperuser
在您的项目中运行以手动创建一个。
Seriously Django? Seriously?
认真的姜戈?严重地?
The only information I found for this was the one listed above but it didn't work: Unable to create superuser in django due to not working in TTY
我为此找到的唯一信息是上面列出的信息,但它不起作用: 由于不在 TTY 中工作,无法在 django 中创建超级用户
And this other one here, which is basically the same: Can't Create Super User Django
另一个在这里,基本相同: 无法创建超级用户 Django
采纳答案by Evgeny Bobkin
If you run
如果你跑
$ python manage.py createsuperuser
Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser
in your project to create one manually.
从 Git BashGit Bash并面对上述错误消息尝试附加winpty
winpty
ie 例如:$ winpty python manage.py createsuperuser Username (leave blank to use '...'):
To be able to run python
commands as usual on windows as well what I normally do is appending an alias line to the ~/.profile
file i.e.
为了能够python
像往常一样在 Windows 上运行命令,我通常做的是在~/.profile
文件中附加一个别名行,即
MINGW64 ~$ cat ~/.profile
alias python='winpty python'
After doing so, either source the ~/.profile
file or simply restart the terminal and the initial command python manage.py createsuperuser
should work as expected!
执行此操作后,获取~/.profile
文件或简单地重新启动终端,初始命令python manage.py createsuperuser
应按预期工作!
回答by marke
I had same problem when trying to create superuser in the docker container with command:
sudo docker exec -i <container_name> sh
. Adding option -t solved the problem:
试图用命令泊坞窗容器中创建超级用户,当我有同样的问题:
sudo docker exec -i <container_name> sh
。添加选项 -t 解决了问题:
sudo docker exec -it <container_name> sh
sudo docker exec -it <container_name> sh
回答by darrell
To create an admin username and password, you must first use the command:
要创建管理员用户名和密码,您必须首先使用以下命令:
python manage.py migrate
python manage.py 迁移
Then after use the command:
然后在使用命令后:
python manage.py createsuperuser
python manage.py createsuperuser
Once these steps are complete, the program will ask you to enter:
完成这些步骤后,程序将要求您输入:
- username
- password
- 用户名
- 电子邮件
- 密码
With the password, it will not show as you are typing so it will appear as though you are not typing, but ignore it as it will ask you to renter the password. When you complete these steps, use the command:
使用密码时,它不会在您键入时显示,因此看起来好像您没有键入,但请忽略它,因为它会要求您租用密码。完成这些步骤后,请使用以下命令:
python manage.py runserver
python manage.py runserver
In the browser add "/admin", which will take you to the admin site, and then type in your new username and password.
在浏览器中添加“/admin”,它会将您带到管理站点,然后输入您的新用户名和密码。
回答by darrell
I figured out how to do so. What I did was I went to VIEWS.py. Next, I imported the module os
. Then I created a function called createSuperUser(request):
. Then, I then created a variable called admin
and set it equal to os.system("python manage.py createsuperuser")
. Then after that, return admin
. Finally, I restarted the Django site, then it will prompt you in the terminal.
我想出了如何做到这一点。我所做的是访问 VIEWS.py。接下来,我导入了模块os
。然后我创建了一个名为createSuperUser(request):
. 然后,我创建了一个名为的变量admin
并将其设置为等于os.system("python manage.py createsuperuser")
. 然后在那之后,返回admin
。最后,我重新启动了 Django 站点,然后它会在终端中提示您。
import os
def createSuperUser(request):
admin = os.system("python manage.py createsuperuser")
return
回答by Harsha Dhagay
In virtualenv, for creating super-user for Django project related to git-bash use the command:
在 virtualenv 中,为与 git-bash 相关的 Django 项目创建超级用户,请使用以下命令:
winpty python manage.py createsuperuser.