-1

I'm getting a response from an API that formats URLs like: http:\/\/domain.com\/. How do I make them normal URLs?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Brenden
  • 8,264
  • 14
  • 48
  • 78

2 Answers2

0

Simply do:

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

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.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
second
  • 28,029
  • 7
  • 75
  • 76
  • 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
-1

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

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284