👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I have a Django form with a RegexField
, which is very similar to a normal text input field.
In my view, under certain conditions I want to hide it from the user, and trying to keep the form as similar as possible. What"s the best way to turn this field into a HiddenInput
field?
I know I can set attributes on the field with:
form["fieldname"].field.widget.attr["readonly"] = "readonly"
And I can set the desired initial value with:
form.initial["fieldname"] = "mydesiredvalue"
However, that won"t change the form of the widget.
What"s the best / most "django-y" / least "hacky" way to make this field a <input type="hidden">
field?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Change a Django form field to a hidden field, check other ast Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Change a Django form field to a hidden field
- Deutsch Change a Django form field to a hidden field
- Français Change a Django form field to a hidden field
- Español Change a Django form field to a hidden field
- Türk Change a Django form field to a hidden field
- Русский Change a Django form field to a hidden field
- Português Change a Django form field to a hidden field
- Polski Change a Django form field to a hidden field
- Nederlandse Change a Django form field to a hidden field
- 中文 Change a Django form field to a hidden field
- 한국어 Change a Django form field to a hidden field
- 日本語 Change a Django form field to a hidden field
- हिन्दी Change a Django form field to a hidden field
Boston | 2023-03-31
Maybe there are another answers? What Change a Django form field to a hidden field exactly means?. Will get back tomorrow with feedback
Boston | 2023-03-31
Simply put and clear. Thank you for sharing. Change a Django form field to a hidden field and other issues with StackOverflow was always my weak point 😁. I just hope that will not emerge anymore
Rome | 2023-03-31
Maybe there are another answers? What Change a Django form field to a hidden field exactly means?. I just hope that will not emerge anymore