Django: How to build a custom form widget?

后端 未结 5 1602
一生所求
一生所求 2020-11-28 23:23

I am having a difficult time finding documentation on how to write a custom widget.

My questions are:

  • If I build a custom widget, can it be used equiva
5条回答
  •  盖世英雄少女心
    2020-11-29 00:26

    NOTE: There are three questions here. For the first two questions, see the fuller answer by AndiDog. I'm only answering the third question here:

    Q. What widget method is responsible for going from the user's input back to the data model?

    A. The value_from_datadict method -- it's sort of the inverse of a widget's render method. This method is presumably what the Django docs on widgets are referring to when it says "The widget handles the rendering of the HTML, and the extraction of data from a GET/POST dictionary that corresponds to the widget." There's nothing further on this point in the docs, but you can see how it works from the code for the built-in widgets.

提交回复
热议问题