How do I hide the field label for a HiddenInput widget in Django Admin?

前端 未结 10 1083
谎友^
谎友^ 2020-12-31 02:34

I\'ve got a bit of Django form code that looks like this:

class GalleryAdminForm(forms.ModelForm):
    auto_id=False
    order = forms.CharField(widget=forms         


        
10条回答
  •  执念已碎
    2020-12-31 03:33

    Oraculum has got it right. You shouldn't be cleaning this up on the client side. If it is clutter, then you shouldn't be sending it to client at all. Building on Oraculum's answer, you should use a custom form template because you you probably still want the hidden values in the form.

    {% for field in form.visible_fields %}
        
    {{ field.errors }} {{ field.label_tag }}
    {{ field }}
    {% endfor %} {% for field in form.hidden_fields %}
    {{ field }}
    {% endfor %}

    Using a custom form template to control hidden fields is cleaner because it doesn't send extraneous info to the client.

提交回复
热议问题