Django - Working with multiple forms

前端 未结 1 1938
梦毁少年i
梦毁少年i 2020-12-02 07:59

What I\'m trying to do is to manage several forms in one page, I know there are formsets, and I know how the form management works, but I got some problems with the idea I h

相关标签:
1条回答
  • 2020-12-02 08:51

    Use the prefix kwarg

    You can declare your form as:

    form = MyFormClass(prefix='some_prefix')
    

    and then, as long as the prefix is the same, process data as:

    form = MyFormClass(request.POST, prefix='some_prefix')
    

    Django will handle the rest.

    This way you can have as many forms of the same type as you want on the page

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