From the documentation, the context dictionary needs to have the same variable name as the template variable. Is there a way to avoid duplicating the variable names and hard coding them when creating the context dictionary?
Example:
Template :
<h1>{{ title }}</h1>
<h4> {{ date }}</h4>
<p> {{ write_up }}</p>
The keys in the context dictionary needs to have the same names as the template as follows:
{
'title': 'some_value',
'date': 'some_date',
'write_up': 'some_other_value'
}
Is there a way to prevent hard coding the values in both places, or to share the values via a constants file? So that the template and context dictionary would look something like this.
<h1>{{ CONST.title }}</h1>
<h4> {{ CONST.date }}</h4>
<p> {{ CONST.write_up }}</p>
{
CONST.title: 'some_value',
CONST.date: 'some_date',
CONST.write_up: 'some_other_value'
}
This way, we prevent duplicating the variable names.