python - Creating a resuable template in Django -
question 1:
so i'm working on template email in django. email has table in it, , need put formatting each row of table because email clients require css styles inline. created template implement table row, , i'm calling with
each row.
row template
<tr style="blahblah"> <td>{{ description}}</td> <td>{{ value}}</td> </tr>
then i'm able call template
{% include 'included_template.html description=some_context_var value=some_other_var %}
all right world, until need other context variable go in 1 of table cells. in case, need reformat datetimefield in date format so:
{{ create_date| date:"n j, y" }}
the above works fine, when do:
{% include "included_template.html" description="date:" value=create_date| date:"n j, y" %}
i error:
django.template.base.templatesyntaxerror: not parse remainder: '|' 'invoice.create_date|'
question 2:
i have cases want compose multiple values 1 of cells, e.g.:
hi {{first_name}} {{last_name}}
is there way can yield parent template render body, or compose variables need within template pass included template? can add stuff context doesn't sit me, since date format function need doesn't seem available on python side.
question 1:
although works:
{{ create_date| date:"n j, y" }}
it should (note space has been removed before date
):
{{ create_date|date:"n j, y" }}
with change, following should work:
{% include "included_template.html" description="date:" value=create_date|date:"n j, y" %}
question 2:
you can use django's built-in template tags
{% full_name=first_name|add:" "|add:last_name %} hi {{ full_name }} {% endwith %}
one warning: if use add
on 2 numbers, sum, not concatenation.
Comments
Post a Comment