2015-02-03 17 views
8

CMD'de ayarlanmış bir hesabı silmek için django'da özel bir komut yaptım, ancak python dosyasını çalıştırabilmek ve komut satırının silinmesini istediğiniz hesap numarası için bana sormasını istiyorum. Şimdiye kadar sahip olduğum şey bu.Django özel komutundan giriş ister misiniz?

from django.core.management.base import BaseCommand, CommandError 
from accounts.models import client 

class Command(BaseCommand): 

    args = '<client_id client_id ...>' 
    help = 'Closes the specified account.' 

    def handle(self, *args, **options): 
     for client_id in args: 
      try: 
       x = client.objects.get(pk=int(client_id)) 
      except client.DoesNotExist: 
       raise CommandError('Client "%s" does no exist' % client_id) 

      x.delete() 

      self.stdout.write('Successfully closed account "%s"' % client_id) 

cevap

9

kullanın dahili raw_input() fonksiyonu:

def handle(self, *args, **options): 
    if args: 
     ids = args 
    else: 
     ids = raw_input('Enter comma-delimited list of ids: ').split(',') 
    for client_id in ids: 
     ... 
+3

'girişi() 'Python 3 http://stackoverflow.com/questions/954834/how-do-i-use-raw -Input-in-piton-3 –

İlgili konular