2016-08-16 35 views
-1

form.py__init __()は、正確に4つの引数(与えられた1)

class InvoiceForm(ModelForm,): 

    def __init__(self,em,first,last): 
     self.email=em 
     self.first=first 
     self.last=last 
     super(InvoiceForm,self).__init__(self,em,first,last) 
     self.fields['email']=forms.ChoiceField(choices=[x.email for x in AuthUser.objects.filter(email=em)]) 
     self.fields['first']=forms.ChoiceField(choices=[x.first_name for x in AuthUser.objects.filter(first_name=first)]) 
     self.fields['last']=forms.ChoiceField(choices=[x.last_name for x in AuthUser.objects.filter(last_name=last)]) 
    total_credits_ordered=forms.IntegerField(label=mark_safe('<br/> total_credits_ordered')) 
    total_mobile_cr_ordered=forms.IntegerField(label=mark_safe('<br/> total_mobile_cr_ordered')) 
    total_cloud_cr_ordered=forms.IntegerField(label=mark_safe('<br/> total_cloud_cr_ordered')) 
    invoice_currency=forms.CharField(label=mark_safe('<br/> invoice_currency'),max_length=100) 
    invoice_currency_code=forms.IntegerField(label=mark_safe('<br/>invoice_currency_code ')) 
    invoice_country=forms.CharField(label=mark_safe('<br/> invoice_country'),max_length=100) 
    invoice_note=forms.CharField(label=mark_safe('<br/> invoice_note'),max_length=100) 


    class Meta: 
     model=Invoices 
     fields=['total_credits_ordered','total_mobile_cr_ordered','total_cloud_cr_ordered','invoice_currency','invoice_currency_code','invoice_country','invoice_note'] 

views.py

def test(request): 
    from app.tests import model_tests 
    m = model_tests() 
    print "assf" 


    try: 

     if request.method=="POST": 
      print "sff" 
      m.create_user_types() 
      cform=CustomerForm(request.POST) 
      if cform.is_valid(): 
       em=cform.cleaned_data['email'] 
       username=email 
       password = cform.cleaned_data['password'] 
       first=cform.cleaned_data['first'] 
       last=cform.cleaned_data['last'] 
       companyname=cform.cleaned_data['company_name'] 
       companyaddr=cform.cleaned_data['company_addr'] 
       companystate=cform.cleaned_data['company_state'] 
       companycountry=cform.cleaned_data['company_country'] 
       id=m.create_customer(username,email,password,first,last,companyname,companyaddr,companystate,companycountry) 
       print "SFsfg" 
       iform=InvoiceForm(email,first,last) 
       print "ggg" 
       if iform.is_valid(): 
        tco=iform.cleaned_data['total_credits_ordered'] 
        tmco=iform.cleaned_data['total_mobile_cr_ordered'] 
        tcco=iform.cleaned_data['total_cloud_cr_ordered'] 
        ic=iform.cleaned_data['invoice_currency'] 
        icc=iform.cleaned_data['invoice_currency_code'] 
        c=iform.cleaned_data['invoice_country'] 
        inote=iform.cleaned_data['invoice_note'] 
        id_i=m.create_invoices(id,tco,tmco,tcco,ic,icc,c,inote) 
        pform=PaymentForm() 
        print "dsf" 
        pform=PaymentForm(request.POST) 
        if pform.is_valid():    
         tpm=pform.cleaned_data['total_payment_made'] 
         ps=pform.cleaned_data['payment_status'] 
         pt=pform.cleaned_data['payment_type'] 
         m.create_payment(id_i,tpm,ps,pt)  
         return HttpResponse("test successful") 
     else: 
      print "d" 
      cform=CustomerForm() 
      iform=InvoiceForm() 
      pform=PaymentForm()          
     return render(request, 'test.html', {'cform': cform,'iform':iform,'pform':pform}) 
    except Exception as e: 
     return HttpResponse("Exception : %s" %(e)) 
    return HttpResponse("Tests Successfull...") 

それが表示されとります Exception : __init__() takes exactly 4 arguments (1 given)

を、私はにパラメータを渡しましたフォーム。

+1

あなたは本当ですか?私は、あなただけでなく、メッセージをstacktraceを含める – Sayse

+1

していないことを下から6行であることをラインで見ることができます。 –

+0

[\ _ \ _ init \ _ \ _()の重複は2つの引数(1つの引数)をとりますか?](https://stackoverflow.com/questions/25805194/init-takes-exactly-2-arguments-1-与えられた) –

答えて

1

私たちは、問題のスタックトレースを持っていないが、問題は、おそらくここにある:ここで

else: 
    print "d" 
    cform=CustomerForm() 
    iform=InvoiceForm() 
    pform=PaymentForm() 

は、あなたが任意のパラメータを渡さずにオブジェクトを作成しています。インスタンス自体が常に渡されているので、メッセージはそれが私はそれがサイレントエラーを回避するために有用なものか、このような警告を行いませんので、あなたがelse部分の後にすべてのものを削除することを示唆しているem,first,last

ある他のパラメータを逃すことを言う:

else: 
    print("Unsupported method "+request.method) 
+0

あなたはどうすればいいか教えてください。 – jersy

+0

愚かな質問をして申し訳ありません。 – jersy

+0

あなたのフォームでは、self、em、firstとlastの4つのパラメータを期待してフォームに__init__を伝えています。だから、CustomerForm()のような引数を使わずにフォームを宣言すると、init関数は 'self'だけが渡されているので、他の3つのものを探しています。 emを最初と最後にデフォルトを割り当てる必要があります。 – jangeador

関連する問題