django-admin
Is Django's command-line utility management tasks, manage.py
and functions the same as him, but it is the django-admin
manager when you create a project created for each project
Note:
django-admin
andmanage.py
although the vast majority of total command, but it is recommended to use the project operationmanage.py
,django-admin
the environment variable is not setDJANGO_SETTINGS_MODULE
or not before callingsettings.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 makemessages creation of the .po file compiled to .mo file, 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 , PASSWORD connection parameter set specified in the like, is ENGINE disposed in the specified database engine runs command line client |
diffsettings | Displays the current settings file and Django default setting (or --default the 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_label migration (including migration_name inside) 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
View the current version of Django
django-admin version
Use the system checks the entire framework to check the Frequently Asked Questions Django project.
By default, it will check all applications.
- To check the application portion of the application by providing a list of tag as a parameter
py manage.py check auth admin myapp
- Barring checks only as belonging to a particular category of inspection
py manage.py check --tag models --tag compatibility
- Displaying a label detection limit
py manage.py check --list-tags
admin
caches
database
models
staticfiles
templates
translation
urls
指定将在其中创建缓存表的数据库
py manage.py createcachetable --database DATABASE
- 显示当前设置文件和Django默认设置之间的差异
py manage.py diffsettings
- 显示所有设置
py manage.py diffsettings --all
将与应用程序名称关联的数据库中的所有数据输出到标准输出
如果未提供应用程序名称,则所有安装的应用程序将被输出
- 输出所有应用程序关联的数据库中的所有数据
py manage.py dumpdata
- 输出所有指定应用程序关联的数据库中的所有数据
py manage.py dumpdata myapp
- 指定格式输出
py manage.py dumpdata --format xml
支持的序列选项有 json(默认), xml, yaml
- 排除指定应用程序
py manage.py dumpdata --exclude=myapp1
- 将所有数据保存
py manage.py dumpdata myapp > myapp_dump.json
-
其他选项
--indent
输出中使用的缩进空间的数量--database
指定转储数据的数据库--natural-primary
省略此对象的序列化数据中的主键--pks PRIMARY_KEYS
仅输出由逗号分隔的主键列表指定的对象--output, -o
指定要写入序列化数据的文件
从数据库中删除所有数据。已应用的迁移不会被删除。只删除具体数据,不删除数据表!
py manage.py flush
- inspectdb
根据数据库中的表生成models文件
py manage.py inspectdb
加载数据到数据库
py manage.py loaddata myapp_dump.json
- 对当前模型进行创建或更改迁移
py manage.py makemigrations
- 解决迁移冲突
py manage.py makemigrations --merge
- 对指定应用程序创建或更改迁移
py manage.py makemigrations myapp
- 将数据库状态与当前的模型和迁移集同步
py manage.py migrate
- 指定应用程序进行迁移同步
py manage.py migrate myapp
- 指定迁移文件进行同步
py manage.py migrate 0001
- 运行服务器
py manage.py runserver
默认 127.0.0.1:8000
- 使用IPv6开发服务器
py manage.py runserver -ipv6 或 django-admin runserver -6
默认 ::1:8000
- 使用指定指定端口
py manage.py runserver 7000
- 使用localhost
py manage.py runserver localhost:8000
- 启动Python交互解释器
py manage.py shell
- 指定shell启动交互解释器
py manage.py shell -i ipython 或 py manage.py shell -i bpython 或 py manage.py shell -i python
- 显示项目中的所有迁移
py manage.py showmigrations
- 显示指定应用程序的所有迁移
py manage.py showmigrations myapp
打印将对该flush 命令执行的SQL语句
py manage.py sqlflush
输出指定应用程式迁移的SQL语句
py manage.py sqlmigrate myapp 0001
创建应用程序
py manage.py startapp myapp
- 在当前目录创建项目
django-admin startproject dome
- 在指定目录创建项目
django-admin startproject dome /Users/jairo/project/myproject
创建超级管理员账户
py manage.py createsuperuser
为超级管理员账户修改密码
py manage.py changepassword admin