On May 10, 1:58 am, Danne <pingvingr...@gmail.com> wrote:
> I'm using the Tumblr (http://www.tumblr.com) REST Api, and keys in
> returned json contains the character "-", like "post": {"regular-
> title": "asdf" .....}. I'm having trouble printing this in the django
> templates since regular-title is an invalid variable name. I've tried
> stuff like: post["regular-title"], post[regular-title], post.regular-
> title and so on, and searched around the docs and mailing lists, but
> haven't found any answers.
>
> Is there a way to print template variables with "-" in their names?

Django templates don't use brackets in dictionary lookups, so
post.regular-title would be the correct syntax.

How are you getting the data from Tumblr into the template? If the API
is returning JSON, at some point (before you parse it) it's just a
string, so you could do x.replace('regular-title', 'regular_title') to
convert the keys into valid Python variables, if that is indeed the
cause of your problem.

It would probably help if you posted your view code.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to