is a command line tool that is automatically generated in the root directory when we create a Django project, it can execute some simple commands, its function is to put the Django project into the directory, and at the same time set theDJANGO_SETTINGS_MODULE
The environment variable is the current project's file.
The code for this looks like this:
#!/usr/bin/env python import os import sys if __name__ == "__main__": ("DJANGO_SETTINGS_MODULE", "adl_lrs.settings") from import execute_from_command_line execute_from_command_line()
The excuse_from_command_line() function parses the name of the command based on the command line argument and calls the corresponding Command to execute the command based on the command name.Commands are located under the commands module of each management module.
So to customize the manage command, you just need to create the target file in the commands directory of the management directory under the app.
Note that not all .py files will be recognized as commands, they need to refer to BaseCommand in order to be recognized correctly, and our command class has to inherit from BaseCommand in order to do so.
Sample code:
from import BaseCommand,CommandError import datetime import pytz class Command(BaseCommand): def handle(self, *args, **options): now=() now=(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0).replace(tzinfo=('UTC')) br1=(2016,6,29) br1=(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0).replace(tzinfo=('UTC')) br2=now print br1,br2
summarize
Above is this article on Django custom manage command example code all content, I hope to help you. Interested friends can continue to refer to other related topics on this site, if there are inadequacies, welcome to leave a message to point out. Thank you for the support of friends on this site!