Django error: got multiple values for keyword argument

前端 未结 3 1556
你的背包
你的背包 2020-12-31 00:51

I get the following error when instantiating a Django form with a the constructor overriden:

__init__() got multiple values for keyword argument \'collection         


        
3条回答
  •  一个人的身影
    2020-12-31 01:25

    It's pretty simple: you pass request.POST and only afterward you put argument for collection_type. Onto what request.POST will be put? There is not place for that. Watch this:

    In [8]: class A:
       ...:     def __init__(self, a, *args):
       ...:         print a, args
       ...:         
       ...:         
    
    In [9]: A(None, a=None)
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    
    /home/gruszczy/Programy/logbuilder/ in ()
    
    TypeError: __init__() got multiple values for keyword argument 'a'
    

    Move request.POST somewhere else in the call, but remember, that named arguments come after the ones, that aren't.

提交回复
热议问题