Within a template distinguish between create and update form

前端 未结 3 1596
轻奢々
轻奢々 2021-01-01 16:13

If the CreateView and UpdateView are using the same template \"model_form.html\" then within the template how would I differentiate if I am creating or updating a form?

3条回答
  •  自闭症患者
    2021-01-01 16:41

    In an update view, there'll be a form.instance, and form.instance.pk will not be None. In a create view, there may or may not be form.instance, but even if there is form.instance.pk will be None.

提交回复
热议问题