创建django项目后先注册APP再make migrations,不然可能会报找不到自定义命令的错误
1.在django指定APP目录下创建management及commands文件夹(ps:记得在这两个文件夹下加上__init__.py,这样django才会处理成一个包)
2.在commands下创建命令py文件(名字根据你的需要命名,没有限制,我这里命名为demo.py,文件名即为命令名称)
3.编辑demo.py,写入命令逻辑代码
#coding: utf-8
'''
Created on 2017年5月31日
@author: win7
'''
from django.core.management.base import BaseCommand
class Command(BaseCommand): # 继承BaseCommand类,类名请保证为Command
def handle(self, *args, **options): # 重写handle方法,该方法写入自定义命令要做的事(逻辑代码)
print 'hello world.'
4.命令测试