Raw Strings with Variables

Chris Rebert clp2 at rebertia.com
Tue Aug 18 21:00:56 EDT 2009


On Tue, Aug 18, 2009 at 5:51 PM, WilsonOfCanada<wwn1 at sfu.ca> wrote:
> However, when I send the list over as a dictionary for HTML:
>
> d["places"] = arrPlaces
>
> return render_to_response('rentSearch.html', d)
>
> the HTML using Django has:
>
> {{ places }} but returns ['C:\\moo', 'C:\\supermoo']

As we've explained already, containers (such as dictionaries and
lists) use repr() to display their elements, and repr() for strings
shows the escape sequences (e.g. \\ \t \n) and adds surrounding
quotes. Hence the output you're getting.
If you don't like the way it looks, then either send the list through
a filter that outputs it like you want by accessing the elements
individually, or iterate over the contents of the list in your
template and output it like you want.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list