Is there any shortcut to display all the fields of a model without explicitly specifying in Django?

We can create a model form very easily in Django just by passing a model form from views to the templates and displaying it as:

{{ form.as_table }}

Do we have similar way so that we do not have to type all the model's fields name in templates to display them?

The models.Model class doesn't have a method similar to .as_table().

You can use .get_fields() to make a similar thing. For example Foo._meta.get_fields() return a tuple of fields associated with the model Foo. Here is the official doc.

The key is the field's type and the value is the field's name. You can loop in values.

Back to Top