Django - Mixing ListView and CreateView

后端 未结 4 1288
无人共我
无人共我 2020-12-14 11:55

I\'m want to create one page with a form, and every time I submit the form it adds an item to the list below the form.

I can make it work using 2 pages:

4条回答
  •  情话喂你
    2020-12-14 12:18

    Do not mix list and update views.
    Instead, create two separate views for these tasks:

    List view displays the list and a web form with action URL pointing to the create view.
    Create view accepts POST data and

    • displays form with error message in case of failure;
    • redirects to the list view in case of success.

    Also I've tried to use class-based views and found that they are too complex.
    I think it is much easier to use old-style function views.

提交回复
热议问题