I would like to read a string from an excel-file with both HTML- and Django-Tags (e.g. "Your current < b > account balance </ b > is: {{ current_balance }}"). I then pass the variable from the python-file to the Django-template (name e.g. balance). When I try to call the variable in the Django-template using {{ balance }}, I get the displayed the whole variable as a string. If I use {{ balance | safe }} the HTML-tags are executed. Is there a way such that the Django tags get executed as well?
Here's my code:
In pages.py:
class page(Page):
def vars_for_template(self): #define variables to pass to tempalte
loc = ("file.xlsx")
# To open Workbook
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
# For row 0 and column 0
variable = sheet.cell_value(0, 1))
print(title)
return dict(
variable=variable
)
In page.html:
{% extends "global/Page.html" %}
{% load staticfiles otree %}
{% block title %}
{% endblock %}
{% block content %}
{{ variable | safe }}
{% endblock %}
the value of variable
is the current value is <b>{{ Constants.value }}</b>
In the output, only the HTML-tags get executed an I receive "the current value is {{ Constants.value }}". Is it possible to display the actual value of the variable Constants.value
?