Use Django django-admin and manage.py commands

django-adminIs Django's command-line utility management tasks, manage.pyand functions the same as him, but it is the django-adminmanager when you create a project created for each project

Note: django-adminand manage.pyalthough the vast majority of total command, but it is recommended to use the project operation manage.py, django-adminthe environment variable is not set DJANGO_SETTINGS_MODULEor not before calling settings.configure()the case would be an error

django-admin and total command manage.py

command Features
version View the current version of Django
check Check that the entire Django project exists Frequently Asked Questions
compilemessages By the makemessagescreation of the .pofile compiled to .mofile, used in conjunction with the built-in support for text
createcachetable Use the information to set file cache table is created for use with the database cache backend
dbshell In use USER, PASSWORDconnection parameter set specified in the like, is ENGINEdisposed in the specified database engine runs command line client
diffsettings Displays the current settings file and Django default setting (or --defaultthe difference between the other set of specified files)
dumping data The output of all data in the database associated with the name of the application to the standard output
flush Delete all data from the database, and then re-sync to perform all post-processing program. Migrate the application will not be cleared
inspectdb The Django model module (the models.py files) to the standard output.
loaddata Search for the specified fixtures (sequence of sets of content files database) and loaded into the database contents
makemessages Throughout the source code directory tree currently running, and pulling all the strings marked for translation.
makemigrations Change or create a new model based on the detected migration
migrate The state database is synchronized with the current model and set of migration
runserver Start of lightweight development Web server on the local computer
send test mail Send a test email to the designated recipient (sent by e-mail to confirm the validity of Django)
shell Start Python interactive interpreter
showmigrations All display items in the migration
sqlflush Print command will flush SQL statement executed
sqlmigrate Print the name of the SQL Migration
sqlsequencereset Print SQL statements to reset the application name given sequence
squashmigrations If possible, the app_labelmigration (including migration_nameinside) compressed into a smaller migration.
startapp Create a Django application directory structure for the given application name given in the current directory or directory
start project Create a Django project directory structure in the current directory or the given directory for a given project name
test Run tests for all applications installed
testserver Django development server to run using data from a given fixture is (as with the runserver)

To the command of the application

command Features
changepassword Change User Password
createsuperuser Create a super user account (user with all privileges)
remove_stale_contenttypes Delete obsolete content type (deleted from the model) from a database
clearsessions You can schedule tasks to run as a job, you can remove expired session directly.
collectstatic Will be collected into a static fileSTATIC_ROOT
findstatic Use enabled Finder search for one or more of the relative path

Common Commands

  • version

View the current version of Django

django-admin version
  • check

Use the system checks the entire framework to check the Frequently Asked Questions Django project.

By default, it will check all applications.

  1. To check the application portion of the application by providing a list of tag as a parameter
py manage.py check auth admin myapp
  1. Barring checks only as belonging to a particular category of inspection
py manage.py check --tag models --tag compatibility
  1. Displaying a label detection limit
py manage.py check --list-tags

admin
caches
database
models
staticfiles
templates
translation
urls

  • createcachetable

指定将在其中创建缓存表的数据库

py manage.py createcachetable --database DATABASE
  • diffsettings

  1. 显示当前设置文件和Django默认设置之间的差异
py manage.py diffsettings
  1. 显示所有设置
py manage.py diffsettings --all
  • dumpdata

将与应用程序名称关联的数据库中的所有数据输出到标准输出

如果未提供应用程序名称,则所有安装的应用程序将被输出

  1. 输出所有应用程序关联的数据库中的所有数据
py manage.py dumpdata
  1. 输出所有指定应用程序关联的数据库中的所有数据
py manage.py dumpdata myapp
  1. 指定格式输出
py manage.py dumpdata --format xml

支持的序列选项有 json(默认), xml, yaml

  1. 排除指定应用程序
py manage.py dumpdata --exclude=myapp1
  1. 将所有数据保存
py manage.py dumpdata myapp > myapp_dump.json
  1. 其他选项

    --indent 输出中使用的缩进空间的数量

    --database 指定转储数据的数据库

    --natural-primary 省略此对象的序列化数据中的主键

    --pks PRIMARY_KEYS 仅输出由逗号分隔的主键列表指定的对象

    --output, -o 指定要写入序列化数据的文件

  • flush

从数据库中删除所有数据。已应用的迁移不会被删除。只删除具体数据,不删除数据表!

py manage.py flush
  • inspectdb

根据数据库中的表生成models文件

py manage.py inspectdb
  • loaddata

加载数据到数据库

py manage.py loaddata myapp_dump.json
  • makemigrations

  1. 对当前模型进行创建或更改迁移
py manage.py makemigrations
  1. 解决迁移冲突
py manage.py makemigrations --merge
  1. 对指定应用程序创建或更改迁移
py manage.py makemigrations myapp
  • migrate

  1. 将数据库状态与当前的模型和迁移集同步
py manage.py migrate
  1. 指定应用程序进行迁移同步
py manage.py migrate myapp
  1. 指定迁移文件进行同步
py manage.py migrate 0001
  • runserver

  1. 运行服务器
py manage.py runserver

默认 127.0.0.1:8000

  1. 使用IPv6开发服务器
py manage.py runserver -ipv6 或 django-admin runserver -6

默认 ::1:8000

  1. 使用指定指定端口
py manage.py runserver 7000
  1. 使用localhost
py manage.py runserver localhost:8000
  • shell

  1. 启动Python交互解释器
py manage.py shell
  1. 指定shell启动交互解释器
py manage.py shell -i ipython 或 py manage.py shell -i bpython 或 py manage.py shell -i python
  • showmigrations

  1. 显示项目中的所有迁移
py manage.py showmigrations
  1. 显示指定应用程序的所有迁移
py manage.py showmigrations myapp
  • sqlflush

打印将对该flush 命令执行的SQL语句

py manage.py sqlflush
  • sqlmigrate

输出指定应用程式迁移的SQL语句

py manage.py sqlmigrate myapp 0001
  • startapp

创建应用程序

py manage.py startapp myapp
  • startproject

  1. 在当前目录创建项目
django-admin startproject dome
  1. 在指定目录创建项目
django-admin startproject dome /Users/jairo/project/myproject
  • createsuperuser

创建超级管理员账户

py manage.py createsuperuser
  • changepassword

为超级管理员账户修改密码

py manage.py changepassword admin
发布了33 篇原创文章 · 获赞 62 · 访问量 24万+

Guess you like

Origin blog.csdn.net/Jairoguo/article/details/104451245