1. 程式人生 > >Python Django manage.py擴充套件自定義命令

Python Django manage.py擴充套件自定義命令

1.建立專案 luffy

django-admin.py startproject luffy

2, 建立app web, 並在settings.py 檔案中新增該app

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模組

 

4.在commands下建eventcheck.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下的內容了