In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?

后端 未结 26 1277
-上瘾入骨i
-上瘾入骨i 2020-11-22 04:09

In a Django form, how do I make a field read-only (or disabled)?

When the form is being used to create a new entry, all fields should be enabled - but when the recor

26条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 04:32

    I think your best option would just be to include the readonly attribute in your template rendered in a or

    rather than include it in the form if it's readonly.

    Forms are for collecting data, not displaying it. That being said, the options to display in a readonly widget and scrub POST data are fine solutions.

提交回复
热议问题