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 Files\JetBrains\PyCharm 2017.2.3\bin\runnerw.exe" C:\Python27\python.exe "E:\Program Files\JetBrains\PyCharm 2017.2.3\helpers\pycharm\django_manage.py" makemigrations E:/Work/django/mydjangoapro
No changes detected

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

manage.py@mydjangoapro > migrate
"E:\Program Files\JetBrains\PyCharm 2017.2.3\bin\runnerw.exe" C:\Python27\python.exe "E:\Program Files\JetBrains\PyCharm 2017.2.3\helpers\pycharm\django_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:\Work\django\mydjangoapro\db.sqlite3
Process finished with exit code 0

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

manage.py@mydjangoapro > createsuperuser
"E:\Program Files\JetBrains\PyCharm 2017.2.3\bin\runnerw.exe" C:\Python27\python.exe "E:\Program Files\JetBrains\PyCharm 2017.2.3\helpers\pycharm\django_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:\Work\django\mydjangoapro\db.sqlite3
Process finished with exit code 0

5)重新進入登錄頁面:http://127.0.0.1:8000/admin,在username中輸入admin,密碼輸入:new.1234,點擊登錄之后成功跳轉到了后台管理頁面:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM