Can I use alias field names in django templates?

I am new to django and python ...

I have a model that includes 10 common attrib_00 fields through attrib_09.

I pass these fields as the django template string context.

I would like to use more meaningful names in the template.

Template strings are retrieved from another model, and I mean adding a field containing a list of related comma-separated names. An idea is the first alias in attrib_00 map lists, the second is attribute_01 ...

I think I need to change the context before rendering so that the public keys are replaced with an alias.

Am I on the right track here?

Is there a better way?

Thanks Ed

PS

(add comment button doesn't work for me?)

I don't have a code yet. Maybe I should explain what I'm trying to achieve ...

, delphi, ebay, - django/python.

/ , . , , , waist_size leg_length. , 10.

, , , _00 " ", .

: - , - , ?

+3
2

, , . - :

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

, DRY, .

Update:
, . , , . , , , {% with %}:

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

, , , .

+5

?

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

attrib_00 .

0

Source: https://habr.com/ru/post/1731182/


All Articles