django通过虚拟环境下的E:\Workspace\venv\django_basic_venv\Scripts目录下
其中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: admin@gmail.com
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.