title: Django: variable in variable in templates
body: <p>Let's assume the following situation. In my database (model) I have a field of description of the task for students. Each student should have their own variant of some variables in the task. So, I save the following model named <code>task</code> in the database:</p>
  
  <pre><code> id | name    | description                                  |
   ---+---------+----------------------------------------------+
    1 | Simple  | This is first task. Answer is {{student_var}}|
  </code></pre>
  
  <p>Method for the view is simple (TeamFlag is a table to correlate teams and tasks: </p>
  
  <pre><code>def render_team(request, team):
      tasks = TeamFlag.objects.filter(team=team)
      return render(request,
                    'team.html',
                    dict({'team': team,
                          'tasks': tasks,
                          'student_var': 'foo',
                          }))
  </code></pre>
  
  <p>In my template:</p>
  
  <pre><code>{% for team_task in tasks %}
      &lt;li class="item"&gt;
          &lt;h6&gt;{{ team_task.task.name }}&lt;/h6&gt;
          &lt;div class="task-content"&gt;{% autoescape off %}
                                    {{team_task.task.description }}
                                    {% endautoescape %}&lt;/div&gt;
  </code></pre>
  
  <p>As the result I see:</p>
  
  <pre><code> This is first task. Answer is {{student_var}}
  </code></pre>
  
  <p>Is there any way in Django to pre-process variables, which are inside the string and pass processed HTML string to the view inside the template, basing on variables (I plan to keep variables in database in K-V format in table with fields like: <code>id</code>, <code>key</code>, <code>value</code>, <code>team_id</code>, <code>task_id</code>).</p>
  
  <p>Generally, I would like to have some method like <code>process_template(html_string, kv-data)</code>, which returns processed HTML string or something similar. I heard about custom filters for the templates, but I'm not sure, whether it's the case or not. </p>
  
  <p>UPD: I successfully added the following code:</p>
  
  <pre><code>tasks = TeamFlag.objects.filter(team=team)
  for tf in tasks:
      data = TaskData.objects.filter(team=team, task=tf.task)
      tf.task.description = Template(tf.task.description).render(
          Context(dict(zip([x.key for x in data],
                           [x.value for x in data]))))
  </code></pre>
  
  <p>However, Django now ignores layout in <code>tf.task.description</code>. My new description looks like: </p>
  
  <p><code>I have some {{temp}} &lt;b&gt;here&lt;/b&gt; and it's {{temp2}}</code></p>
  
  <p>It's being rendered, I can see it in source code of the page, but actually nothing happens. </p>
  
  <p>UPD2: Seems to be CSS problem. Question closed.</p>