Python Django manage.py扩展自定义命令

时间:2022-12-12 18:04:56

1.创建项目 luffy

django-admin.py startproject luffy

2, 创建app web, 并在settings.py 文件中添加该app

Python Django manage.py扩展自定义命令Python Django manage.py扩展自定义命令
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Api
    'web',

]
settings.py

 

3.在web下建management.commands模块

Python Django manage.py扩展自定义命令

 

4.在commands下建eventcheck.py文件

Python Django manage.py扩展自定义命令

 

5.编写eventcheck.py

 

6.执行python manage.py  检查下是否有这个命令


[auth]
  changepassword
  createsuperuser

[contenttypes]
  remove_stale_contenttypes

[django]
  check
  ...
  makemessages
  makemigrations
  migrate
  sendtestemail
  shell
  ...
  startapp
  startproject

 

[web]
  eventcheck

7.执行python manage.py  eventcheck

就会执行  eventcheck.py下的内容了