How to exclude django form field from render but still keep it for validation?

前端 未结 4 508
悲&欢浪女
悲&欢浪女 2021-01-19 17:42

If I have a model (extract):

class Coupon(models.Model):
    image = models.ImageField(max_length=64, null=True, upload_to=\"couponimages\")
<
4条回答
  •  情书的邮戳
    2021-01-19 18:07

    So a better way to exclude just a single field in the template might be:

    
    {% for field in form %}
        {% if field != "image" %}
        
        {% endif %}
    {% endfor %}
    
    {{ field }}

    Beats manually writing out all the fields.

提交回复
热议问题