# myproject/myapp/management/commands/my_command.pyfrom django.core.management.base import NoArgsCommandfrom django.template import Template, Contextfrom django.conf import settingsclass Command(NoArgsCommand): def handle_noargs(self, **options): t=Template("My name is {myname}.") c=Context({"myname":"John"}) f = open('write_test.txt', 'w') f.write(t.render(c)) f.close
然后(如果您遵循文档),您将能够以以下方式执行命令:
python manage.py my_command
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)