title: How to get values from dictionary in jinja when key is a variable?
body: <p>I'm trying to retrieve entries from a python dictionary in jinja2, but the problem is I don't know what key I want to access ahead of time - the key is stored in a variable called <code>s.course</code>. So my problem is I need to double-substitute this variable. I don't want to use a <code>for</code> loop because that will go through the dictionary way more than is necessary. Here's a workaround that I created, but it's possible that the <code>s.course</code> values could change so obviously hard-coding them like this is bad. I want it to work essentially like this:</p>
  
  <pre><code>{% if s.course == "p11" %}
      {{course_codes.p11}}
  {% elif s.course == "m12a" %}
      {{course_codes.m12a}}
  {% elif s.course == "m12b" %}
      {{course_codes.m12b}}
  {% endif %}
  </code></pre>
  
  <p>But I want it to look like this:</p>
  
  <pre><code>{{course_codes.{{s.course}}}}
  </code></pre>
  
  <p>Thanks!</p>