Django(trunk) and class based generic views: one form's initial data appearing in another one's

前端 未结 2 336
难免孤独
难免孤独 2021-01-28 02:45

I\'ve run into a strange problem where data seems to persist accross different views and requests until the server gets restarted.

I\'ve managed to reduce the issue to t

2条回答
  •  囚心锁ツ
    2021-01-28 03:13

    Because you're mutating the kwargs that are passed in, which come from class-level properties in the view class.

    Instead, copy them and update the copy:

    initial_defaults = {'bug': 'no'}
    initial_defaults.update(kwargs.get('initial', {}))
    defaults = kwargs.copy()
    defaults['initial'] = initial_defaults 
    

提交回复
热议问题