今天是基督文明的傳統節日聖誕節。作為一名靠大樂透來實現買房買車夢想的社畜。怎麼可能這麼早享受節日時光。所以就久了下面這些文字。用來記錄一下無聊的下午時光。
本片主要記錄Django 中新增一些便利的command 工具的方法。
主要就是繼承了 Django 自己的基礎 command 工具類。
from django.core.management import BaseCommand, CommandError
from django.core.management.base import no_translations
class Command(BaseCommand):
pass
必須要實現的方法
def add_arguments(self, parser):
pass
def handle(self, *args, **options)
pass
handle 方法主要用來實現命令列的功能。
options 中攜帶了從command 指令中穿透過來的引數以及相關值。
add_arguments 方法主要用來處理 指令中需要攜帶的引數,以及相關值。
以上就可以實現一個簡陋的 Django command 工具。
如果需要更多複雜的內容可以參閱writing custom django-admin command tool