modelform을 사용하면서 model 에 정의되지 않는 별도의 사용자 필드를 추가해야 하는 경우가 많다. (ㅋ 나만 그런가) 암튼 이런경우, 템플릿에서는 안 보이기를 원하는 것이 당연하다.
<input type="hidden" name="form-0-instance_id" value="106" id="id_form-0-instance_id">
이미 준비되어 있다 장고는 대부분이
forms.HiddenInput()
class TagStatusForm(forms.ModelForm):
class Meta:
model = TagStatus
widgets = {'tag': forms.HiddenInput()}
https://stackoverflow.com/questions/15795869/django-modelform-to-have-a-hidden-input
Django ModelForm to have a hidden input
So I have my TagStatus model. I'm trying to make a ModelForm for it. However, my form requires that the hidden input be populated with the {{ tag.name }}. I've been looking through the docs and I d...
stackoverflow.com
이걸 html template 에서 나오도록 하려면, 아래처럼 하면 된다.
모든 hidden 필드들이 아래 구문에 의해서 출력되도록 되어 있다.
{% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %}
이상.
Taylor Hunt 님의 사진, 출처: Pexels