Validating a form with overloaded _init_

后端 未结 1 438
情歌与酒
情歌与酒 2021-01-28 01:31

I have a form with a new init method, which allow to display various choices according to a parameter :

class Isochrone_Set_Parameters(forms.Form):
             


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-28 02:10

    You've changed the signature to the form initialization, so that the first parameters is now Grid_Type rather than the usual data. This means that when you do form = Isochrone_Set_Parameters(request.POST), the POST is being used for Grid_Type.

    Either make sure you always pass Grid_Type, or (preferably) don't put that in the parameter list at all: get it from kwargs:

    def __init__(self, *args, **kwargs):
        Grid_Type = kwargs.pop('Grid_Type', None)
        super(Isochrone_Set_Parameters, self).__init__(*args, **kwargs)
        ...
    

    (Also, please use PEP8-standard naming conventions: IsochroneSetParameters, grid_type, etc).

    0 讨论(0)
提交回复
热议问题