简体   繁体   English

在 PyCharm 中创建超级用户 Django

[英]Create superuser Django in PyCharm

I'm following the basic tutorial but for some reason any time I try to create a superuser (run manage.py Task --> createsuperuser) I get an error in the program.我正在学习基本教程,但出于某种原因,每当我尝试创建超级用户(run manage.py Task --> createsuperuser)时,我都会在程序中遇到错误。

It returns "Superuser created."它返回“超级用户已创建”。 but after giving me this error:但在给我这个错误之后:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'setup_environ'

When I try to login to 127.0.0.1:8000/admin当我尝试登录到127.0.0.1:8000/admin

I get incorrect credentials.我得到不正确的凭据。 Any thoughts?有什么想法吗?

As of now all I have are django installed through pycharm and python 3.4 and django 1.7.到目前为止,我所有的都是通过pycharmpython 3.4django 1.7.

Well it looks like it is a bug in pycharm 4.3.1 and python 3.4 and django 1.7 I faced the same problem and after searching for a while, I managed to solve the issue through using the command line.好吧,它看起来像是pycharm 4.3.1python 3.4django 1.7一个错误我遇到了同样的问题,经过一段时间的搜索,我设法通过使用命令行解决了这个问题。 In the command line type:在命令行输入:

$python manage.py createsuperuser

then it will ask you for username , type that and press enter.然后它会要求你输入username ,输入并按回车键。 Notice that you might not be able to use the username you used while trying to create the superuser the first time请注意,您可能无法使用您第一次尝试创建超级用户时使用的用户名

then enter an email然后输入email

and a password and reenter the password while entering the password, you will notice it is hiding it and not moving the cursor, don't think it is not getting what you type Then you're done.password并在输入密码时重新输入密码,您会注意到它隐藏了它并且没有移动光标,不要认为它没有得到您输入的内容然后您就完成了。

The reason why you can't use the username from first time is that Django might have created a superuser using that username but it missed up with the password or sth as the discussion from this thread suggests, however, I am not sure of that.您不能从第一次使用用户名的原因是 Django 可能使用该用户名创建了一个超级用户,但它错过了密码或 sth,正如该线程的讨论所暗示的那样,但是,我不确定这一点。

Goto : PyCharm > Tools > Run django Console >转到:PyCharm > 工具 > 运行 django 控制台 >

from django.contrib.auth.models import User
User.objects.create_superuser(username='yourUsername', password='YourPassword', email='your@email.PK')

Cheers !干杯!

Go to cmd or if you are in pycharm, go to Terminal .转到cmd或者如果您在 pycharm 中,请转到Terminal paste it:粘贴它:

python manage.py createsuperuser

Then, follow instructions in terminal.然后,按照终端中的说明进行操作。 all set.搞定。 Now inside terminal,paste it:现在在终端内,粘贴它:

python manage.py runserver

after clicking that local server, add /admin in url.单击该本地服务器后,在 url 中添加 /admin。 in my case:就我而言:

http://127.0.0.1:8000/admin

Give your username and password,it will redirect you to Django administration page.提供您的用户名和密码,它会将您重定向到 Django 管理页面。
upvote if it works...如果有效,请点赞...

Go to Terminal .Paste it:转到终端。粘贴它:

python manage.py createsuperuser

And Then Fill your details like Username, Email and Password.然后填写您的详细信息,例如用户名、电子邮件和密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM