Python Django位置/关键字参数问题,格式为
我在尝试提交表单时遇到了一个Python Django位置/关键字参数问题,格式为,python,django,forms,Python,Django,Forms,我在尝试提交表单时遇到了一个\uuuu init\uuuuuu()为关键字参数“school”获取了多个值的错误。这些论点有些可疑,但我不能完全确定 视图: 表格: 因为你打电话的时候 SectionAddwCourseForm(request.POST, prefix='sctn', school=this_school) request.POST将对应于self之后的部分addwcourseform.\uuu init\uuuu的第一个参数,因此学校。然后用关键字school传递另一个参数
\uuuu init\uuuuuu()为关键字参数“school”获取了多个值的错误。这些论点有些可疑,但我不能完全确定
视图:
表格:
因为你打电话的时候
SectionAddwCourseForm(request.POST, prefix='sctn', school=this_school)
request.POST将对应于self
之后的部分addwcourseform.\uuu init\uuuu
的第一个参数,因此学校
。然后用关键字school
传递另一个参数,因此有多个值。
参数的顺序非常重要 那么,这个问题的解决方案是什么呢?好的,就是把你的参数按你函数所期望的顺序排列。所以先去学校,还是同一条错误信息?我猜你也有一所学校。您需要删除它。这是因为现在位置问题之前有一个关键字arg。好的,只需传递school参数的值,而不带school=
class SectionAddwCourseForm(forms.ModelForm):
class Meta:
model = Section
fields = ['Name','teacher']
labels = {
"Name":"Section Name",
}
def __init__(self, school, *args, **kwargs):
super(SectionAddwCourseForm, self).__init__(*args, **kwargs)
print school
try:
#self.fields['standards'].queryset = self.instance.standards.all() #works to get current ass't stds
self.fields['teacher'].queryset = Teacher.objects.filter(school=school).order_by('LastName')
except:
print "except teacher list for this school"
pass
SectionAddwCourseForm(request.POST, prefix='sctn', school=this_school)