1

So I have been trying to use Bit.ly API to make a small section with link shortening, but I don't want the page to refresh to show me the short link. I am new to Python, and web dev, and this is what I have, I tried looking in google, and here as well, but I don't really know what to ask google for. Thank you for your help in advance.

#!/Python27/python
# Import modules for CGI handling 
import cgi, cgitb 
import requests
import json

# Header
print "Content-type:text/html\r\n\r\n"
print ""

# Create instance of FieldStorage 
form = cgi.FieldStorage() 
#print "form created</br>"

# Get data from fields
long_url = form.getvalue('longurl')
#print str(long_url) + "long url saved to the form field"

# Process the link to the bit.ly
query_params = {'access_token': 'API_KEY',
                'login': 'Yakumanification',
                'longUrl': long_url} 

endpoint = 'https://api-ssl.bitly.com/v3/shorten'
response = requests.get(endpoint, params=query_params, verify=True)

data = json.loads(response.content)
print data ['data']['url']
Yakuman
  • 173
  • 9

1 Answers1

0

Use ajax. You can utilize jquery if you want to utilize post or get via ajax. Google jquery ajax to get more detail.

shaytac
  • 3,789
  • 9
  • 36
  • 44