10👍
✅
You can use use a variable in the static template tag. Note that you don’t need the {{
or }}
{% static SampleModel.0.propertyValue %}
1👍
You can use any variable from your context in Django tags (custom tags may need some adjustments to work with it). In your case, this works fine:
{% static SampleModel.0.propertyValue %}
This usages also work:
{% with my_computed_var=SampleModel.0.propertyValue %}
{% static my_computed_var %}
{% endwith %}
{% static some_var|customFilter %}
See the documentation about custom tags for more information, it is also relevant for Django defaults tags.
- [Django]-ImportError: cannot import name connections
- [Django]-Model integrity check in django
- [Django]-Distinct values with Q objects
- [Django]-Retrieve HTTP Header in Django RestFrameWork
Source:stackexchange.com