Skip to main content

Django: Model attribute looks for field works in view, but not in template

Say I have a model:

from django.db import models

class Foo(models.Model)
    fav_color = models.CharField(max_length=250, help_text="What's your fav color?")

print(Foo.fav_color.field.help_text)  # prints: What's your fav color?

Say I have a view with context:

{
    'Foo': Foo
}

And in a template , the result will be blank. However will print the string representation of the model, so I know the models is getting passed into the template.

Why are the attributes look ups to get the help_text failing in the template, why is the help_text empty in the template?



source https://stackoverflow.com/questions/75592945/django-model-attribute-looks-for-field-works-in-view-but-not-in-template

Comments