django自定义manage.py运行命令

django 自定义命令: $ python manage.py your_commond

-创建你的app
-在你的app下面创建包名为 management , 名字不可以修改
-创建handle_commond.py 文件,这个命名可以自定义

  • 如下图所示:
    这里写图片描述

编辑代码:

#coding: utf-8
import time
from django.core.management import BaseCommand


class Command(BaseCommand):

    def handle(self, *args, **options):
        """
        添加你你的处理逻辑
        """
        print 'hello world!!'

保存完成后运行:

在项目运行命令目录下执行 和 python manage.py runserver 同一个目录
$ python manage handle_commond # 这个命令和刚刚上面创建的handle_commond.py 文件名字必须相同

猜你喜欢

转载自blog.csdn.net/qq_34971175/article/details/79430274