<style>
.nav-pills>li.active>a,
.nav-pills>li.active>a:hover,
.nav-pills>li.active>a:focus {
  background: #d6c19d;
  color: #333;
}
.sidebar .nav>li>a {
  padding: 0.5em 1em;
  color: inherit;
}
.sidebar .nav .nav>li>a {
  margin-left: 1em;
}
.sidebar>.nav>li.active>a:after {
    font-family: 'ForkAwesome', 'FontAwesome';
    content: "\f078";
    float: right;
    color: grey;
}
</style>
<nav class="menu sidebar">
  <ul class="nav nav-pills nav-stacked">
  {% for d in depts %}
    <li class="{{ (dept and dept.id == d.id) ? 'active' }}">
      <a href="{{ path_for('catalog', { 'dept' : d.slug }) }}">
        {{ d.name }}
      </a>  
      {% if dept and dept.id == d.id %}
        <ul class="nav nav-pills nav-stacked">
          {% for s in subdepts %}
            <li class="{{ (subdept and subdept.id == s.id) ? 'active' }}">
              <a href="{{ path_for('catalog', { 'dept' : d.slug,
                                                'subdept' : s.slug }) }}">
                {{ s.name }}
              </a>
          {% endfor %}
        </ul>
      {% endif %}
    </li>
  {% endfor %}
  </ul>
</nav>

<style>
.nav-pills>li.active>a,
.nav-pills>li.active>a:hover,
.nav-pills>li.active>a:focus {
  background: #d6c19d;
  color: #333;
  margin-bottom: 0.5em;
}
.sidebar .nav>li>a {
  padding: 0.5em 1em;
  color: inherit;
}
.sidebar .nav .nav>li>a {
  margin-left: 1em;
}
.sidebar>.nav>li.active>a:after {
    font-family: 'ForkAwesome', 'FontAwesome';
    content: "\f078";
    float: right;
    color: grey;
}
</style>
<nav class="menu sidebar">
  <ul class="nav nav-pills nav-stacked">
  {% for d in depts %}
    <li class="{{ (dept and dept.id == d.id) ? 'active' }}">
      <a href="{{ path_for('catalog', { 'dept' : d.slug }) }}">
        {{ d.name }}
      </a>  
      {% if dept and dept.id == d.id %}
        <ul class="nav nav-pills nav-stacked">
          {% for s in subdepts %}
            <li class="{{ (subdept and subdept.id == s.id) ? 'active' }}">
              <a href="{{ path_for('catalog', { 'dept' : d.slug,
                                                'subdept' : s.slug }) }}">
                {{ s.name }}
              </a>
          {% endfor %}
        </ul>
      {% endif %}
    </li>
  {% endfor %}
  </ul>
</nav>

Add margin after active sidebar link
Add margin after active sidebar link
