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)
但我已經通過參數表格。
您確定嗎?我可以看到,從底部6行,你不 – Sayse
也包括stacktrace,請不僅消息。 –
[\ _ \ _ init \ _ \ _()的可能重複只需要2個參數(給出1)?](https://stackoverflow.com/questions/25805194/init-takes-exactly-2-arguments-1-給定) –