django下命令行工具
django-admin.py是Django的一個用戶管理任務的命令行工具,manage.py是對django-admin.py的簡單包裝,每個Django Project裏面都包含一個manage.py
django-admin
常用的命令:
startproject 創建一個項目
startapp 創建一個app
runserver 運行一個服務器
shell 進入django shell
dbshell 進入django dbshell
check 檢查django項目完整性
flush 清空數據庫
compilemessages 編譯語言文件
makemessages 創建語言文件
makemigrations 生成同步數據庫腳本
migrate 同步數據庫
showmigrations 查看生成的數據庫同步腳本
sqlflush 查看生成清空數據庫的腳本
sqlmigrate 查看數據庫同步的sql語句
dumpdata 到處數據庫
loaddata 導入數據庫
diffsettings 查看當前配置和django默認配置的不同之處
createcachetable
inspectdb
sendtestemail
sqlsequencereset
squashmigrations
test
testserver
manage.py
特有的一些子命令:
createsuperuser 創建超級管理員
changepassword 修改密碼
clearsessions 清除session
創建一個項目hello_django
(django_basic_venv) E:\Workspace\venv>cd E:\Workspace\pycharm
(django_basic_venv) E:\Workspace\pycharm>django-admin.exe startproject hello_django
(django_basic_venv) E:\Workspace\pycharm>
創建一個app,名字為hello
(django_basic_venv) E:\Workspace\pycharm>cd hello_django
(django_basic_venv) E:\Workspace\pycharm\hello_django>django-admin.exe startapp
hello
(django_basic_venv) E:\Workspace\pycharm\hello_django>
數據庫同步:
(django_basic_venv) E:\Workspace\pycharm\hello_django>manage.py makemigrations
No changes detected
(django_basic_venv) E:\Workspace\pycharm\hello_django>manage.py migrate
Operations to perform:
Apply all migrations: contenttypes, auth, sessions, admin
Running migrations:
Rendering model states... DONE
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 sessions.0001_initial... OK
(django_basic_venv) E:\Workspace\pycharm\hello_django>
創建超級管理員並添加密碼(django1.9.5密碼要求復雜度)
(django_basic_venv) E:\Workspace\pycharm\hello_django>manage.py createsuperuser
Username (leave blank to use ‘administrator‘): admin
Email address: [email protected]
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
Password:
Password (again):
Superuser created successfully.
(django_basic_venv) E:\Workspace\pycharm\hello_django>
修改默認啟動端口
(django_basic_venv) E:\Workspace\pycharm\hello_django>manage.py runserver 0.0.0.0:80
Performing system checks...
System check identified no issues (0 silenced).
November 25, 2017 - 08:52:59
Django version 1.9.5, using settings ‘hello_django.settings‘
Starting development server at http://0.0.0.0:80/
Quit the server with CTRL-BREAK.
django下命令行工具