[Django]-Can I use alias field names in django templates?

5👍

I would say to make your aliases in the context before passing from the view to the template. Something along the lines of:

c = Context({'foo': attrib_01, 'bar': attrib_02, ...})

You can plug this into a new function so that you don’t break DRY and you’re good to go.

Update:
As far as actually mapping this within the template, not so much. The template is, after all, just a template. The only thing coming close to working like you’re thinking is a {% with %} block:

{% with attrib_01 as foo %}
   <div class="foo">{{ foo }}</div>
{% endwith %}

It would likely work, but I fear it could get rather ugly.

0👍

How about using translations?

attrib_00 = models.TextField(_('attrib_00'), blank=True, null=True)

And then have different translations for attrib_00 as required.

Leave a comment