title: How to put braces in django templates?
body: <p>I need to produce an id surrounded by braces ( for example "{1234}" ). With the django template language, braces are also used to start a variable substitution, so I have some trouble in obtaining what I want. I tried</p>
  
  <pre><code>{{{ id }}}
  {{ '{'id'}' }}
  {{ '{'+id+'}' }}
  { {{ id }} }
  </code></pre>
  
  <p>None of these methods work, except the last one, which unfortunately produces "{ 1234 }", not what I want. I currently have two solutions : either I pass an id variable already containing the {} (ugly) or I write a custom filter and then write {{ id|add_braces }} (I prefer it). </p>
  
  <p>Before going this way, I prefer to ask if a better solution exists.</p>
  
  <p>Using escaped values does not work. Even if I add {% autoescape off %}%7B{% endautoescape %} I don't get the {, which is strange, but that's another problem.</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit</strong>: I wrote a quick filter. Pasting it here so someone else can use it as a template for writing a more complex one. To be put into python package application_path/templatetags/formatting.py</p>
  
  <pre><code>from django import template
  from django.template.defaultfilters import stringfilter
  
  register = template.Library()
  
  @register.filter
  @stringfilter
  def add_braces(value):
      return "{"+value+"}"
  </code></pre>