Django: Want to display an empty field as blank rather displaying None
Use the built-in default_if_none
filter.
{{ client.user|default_if_none:" " }}{{ client.user|default_if_none:"" }}
this is such a strange problem.I have a good idea for it. If you want to modify your field at display time than rather checking it at template , check it at your model class.
ExampleModel(models.Model): myfield = models.CharField(blank=True, null = True) @property def get_myfield(self) if self.myfield: return self.myfield else: return ""
Use it in your template directly instead of field.
{{ExampleModel.get_myfield}}
you never need to change your template to change this field in future, just modify you property.