Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django位置/关键字参数问题,格式为_Python_Django_Forms - Fatal编程技术网

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)