0

I'm using Django 1.1 on a project, and I ran into a problem.

I need to send a GET request to an external URL. I want to create a method that would act like this:

def Send_msg(object):
    converted_url = "http://example.com/some/link/?title=" 
                    + object.title + "&body=" + object.body
    LoadURL(converted_url)
    return True

Another problem that title and body should be translated to equivalent of rawurlencode() in PHP

I tried to search in Django Docs, but no success.

Tom Carrick
  • 6,349
  • 13
  • 54
  • 78
JackLeo
  • 4,579
  • 9
  • 40
  • 66

1 Answers1

3
def Send_msg(request, object):
    import urllib2, urllib
    base_url = "http://example.com/some/link"
    values = { 'title': object.title, 'body': object.body }
    data = urllib.urlencode(values)
    urllib2.urlopen(base_url+"?"+data).read()                
    return HttpResponse()

Something like this. The request bit is not necessary, depends on your requirements, though.

Uku Loskit
  • 40,868
  • 9
  • 92
  • 93