Django通过pycharm创建后,如何登录admin后台?

问题背景:

使用pycharm创建完成django项目(项目名称为:mydjangopro,app名称为my_blog)

,

本想登录后台直接输入地址:http://127.0.0.1:8000/admin后,登录页面出现了,随便(username:admin,password:admin)输入了账户名和密码却进入了错误黄页:

从错误代码中我们也发现说是数据没有找到表相关问题,从程序工程上此时查看多了一个sqllite的数据库,这说明默认django使用的数据库是sqllite。

解决上边问题的方案:

1)在pycharm的tools->"Run manage.py task...':

直接点击,会在pycharm右侧代码栏下边弹出一个“manage.py@mydjangopro”命令运行窗口。

2)在“manage.py@mydjangopro”命令运行窗口中输入:makemigrations

manage.py@mydjangoapro > makemigrations
"E:Program FilesJetBrainsPyCharm 2017.2.3in
unnerw.exe" C:Python27python.exe "E:Program FilesJetBrainsPyCharm 2017.2.3helperspycharmdjango_manage.py" makemigrations E:/Work/django/mydjangoapro
No changes detected

3)在“manage.py@mydjangopro”命令运行窗口中输入:migrate

复制代码
manage.py@mydjangoapro > migrate
"E:Program FilesJetBrainsPyCharm 2017.2.3in
unnerw.exe" C:Python27python.exe "E:Program FilesJetBrainsPyCharm 2017.2.3helperspycharmdjango_manage.py" migrate E:/Work/django/mydjangoapro
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying sessions.0001_initial... OK
Following files were affected 
 E:Workdjangomydjangoaprodb.sqlite3
Process finished with exit code 0
复制代码

4)在“manage.py@mydjangopro”命令运行窗口中输入:createsuperuser

复制代码
manage.py@mydjangoapro > createsuperuser
"E:Program FilesJetBrainsPyCharm 2017.2.3in
unnerw.exe" C:Python27python.exe "E:Program FilesJetBrainsPyCharm 2017.2.3helperspycharmdjango_manage.py" createsuperuser E:/Work/django/mydjangoapro
Username (leave blank to use 'administrator'):  admin
Email address:  admin@admin.com
Warning: Password input may be echoed.
Password:  admin
Warning: Password input may be echoed.
Password (again):  admin
The password is too similar to the email address.
This password is too short. It must contain at least 8 characters.
This password is too common.
Warning: Password input may be echoed.
Password:  new.1234
Warning: Password input may be echoed.
Password (again):  new.1234
Superuser created successfully.
Following files were affected 
 E:Workdjangomydjangoaprodb.sqlite3
Process finished with exit code 0
复制代码

5)重新进入登录页面:http://127.0.0.1:8000/admin,在username中输入admin,密码输入:new.1234,点击登录之后成功跳转到了后台管理页面:

原文地址:https://www.cnblogs.com/zhujiabin/p/8258533.html