0

Possible Duplicate:
How do I un-escape a backslash-escaped string in python?

I'm getting a response from an api that formats URLs like: http:\/\/domain.com\/. How do I make them normal URLs? I feel like there's a template tag that could be used.

UPDATE: I know I can use url.replace('\/', '/'), but I am wondering if there is something in the template I can do. I'm getting a dict back from the Instagram API and that contains the escaped slashes. I'd prefer to make this change in the template instead of having to parse the JSON in the view.

Community
  • 1
  • 1
Brenden
  • 7,387
  • 14
  • 43
  • 73

2 Answers2

1

what, like

url.replace('\/', '/')

edit

there isn't anything built-in, but leaving it as an exercise for you to turn this into a custom template filter. The docs are pretty good. If you get stuck, feel free to post further (specific) questions, (e.g. not "how do i turn this into a custom filter") and we'll be happy to guide you along the way

second
  • 26,808
  • 7
  • 73
  • 75
  • Yea, I just didn't know if there was a way to do it in the template tag, so I dont have to parse through the dict before displaying it – Brenden Jan 05 '12 at 17:32
  • 1
    @Brenden: Your best bet is to write a custom template tag to do that for you. – mipadi Jan 05 '12 at 17:34
  • 3
    Why is this API being called from the template? If possible, I'd do this in the view in python. – Yuji 'Tomita' Tomita Jan 05 '12 at 17:47
  • Sorry for being unclear. The API is being called in the view, and the response is being passed to the template. If I can fix in the template, I dont have to do a for loop over the response to change the URL – Brenden Jan 05 '12 at 18:03
  • I build a custom template tag. Thanks! – Brenden Jan 05 '12 at 18:55
  • @Brenden, if it's being called in the view, I'd definitely try to make these modifications in the view. Building a tag, adding new files, spreading code around seems like a lot of organizational overhead just to make a simple python change. But you may have your reasons - good luck! – Yuji 'Tomita' Tomita Jan 05 '12 at 20:14
0

Use the safe filter as a guide on how to write your own that does this.

Burhan Khalid
  • 161,711
  • 18
  • 231
  • 272