我想知道为什么我的表单没有呈现。我收到的ValueError
错误消息说:
Need more than one value to unpack
我理解它为什么这么说(因为表单显示为类对象<points.forms.OffensiveScoringForm object at 0x10323fed0>
)
forms.py
from django import forms
from django.forms import widgets
SCORING_YARDS = [str(x) for x in range(0,55,5)]
TD_SCORING= [str(x) for x in range(0,11)]
INTERCEPTIONS = [str(x) for x in range(-10,1)]
RECEPTIONS = [str(x) for x in [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.5,2]]
RECEIVING_YARDS = [str(x) for x in range(0,55,5)]
class OffensiveScoringForm(forms.Form):
yards_per_point_passing = forms.ChoiceField(widget=forms.Select, choices=SCORING_YARDS)
points_per_passing_td = forms.ChoiceField(widget=forms.Select, choices=TD_SCORING)
points_per_interception = forms.ChoiceField(widget=forms.Select, choices=INTERCEPTIONS)
points_per_reception = forms.ChoiceField(widget=forms.Select, choices=RECEPTIONS)
yard_per_point_receiving = forms.ChoiceField(widget=forms.Select, choices=RECEIVING_YARDS)
points_per_receiving_td = forms.ChoiceField(widget=forms.Select, choices=TD_SCORING)
yards_per_point = forms.ChoiceField(widget=forms.Select, choices=SCORING_YARDS)
rushing_td = forms.ChoiceField(widget=forms.Select, choices=TD_SCORING)
任何关于为什么我的表单没有呈现的帮助或见解将不胜感激,感谢您的观看。这是我的代码:
views.py
from django.shortcuts import render
from myapp.forms import OffensiveScoringForm
def home(request):
form = OffensiveScoringForm()
return render(request,'base.html',{
'form':form,
})
base.html
<form action = "/nothing/" method="get">
{{ form }}
<input type="submit" value="Submit" />
</form>