Shell commands in Django

shell tools

Django's manage tool provides shell commands to help us configure the running environment of the current project (such as connecting to a database, etc.) so that we can execute test python statements directly in the terminal.

Enter the shell through the following command

python manage.py shell

Insert picture description here
Import two model classes for later use

from book.models import BookInfo,PeopleInfo

This article's shell is a command of the manage tool

Remember the administrator created before, also use the manage command, then let's talk about this manage

Django command line tools

django-admin.py is a command-line tool for managing tasks in Django, manage.py is a simple package for django-admin.py, and each Django Project will contain a manage.py

grammar:

django-admin.py <subcommand> [options]
manage.py <subcommand> [options]

subcommand is a subcommand; options are optional

# 常用子命令:

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默认配置的不同之处

Some subcommands specific to manage.py:

createsuperuser:创建超级管理员(*)
changepassword:修改密码(*)
clearsessions:清除session

Change the port of the development server:

python manage.py runserver 8080

View the help documentation:

python manage.py help
D:\day70class>python manage.py help

Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[auth]
    changepassword
    createsuperuser

[contenttypes]
    remove_stale_contenttypes

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver

[sessions]
    clearsessions

[staticfiles]
    collectstatic
    findstatic
    runserver
Published 125 original articles · Like 260 · Visits 120,000+

Guess you like

Origin blog.csdn.net/weixin_44685869/article/details/105368913