def newShortUrl(request): assert request.method == 'POST' surl = ShortURL.create(request.POST['url']) dct = {'short': surl.short()} from django.shortcuts import render_to_response return render_to_response('polls/rawjson.html', {'jsonoutput': simplejson.dumps(dct)})
def lookupShortUrl(request, code): assert request.method == 'GET' dct = {} longUrl = ShortURL.lookup(code) if longUrl is not None: dct['url'] = longUrl if request.GET.has_key('json') and request.GET['json']: response = render_to_response('rawjson.html', {'polls/jsonoutput': json.dumps(dct)}) else: response = render_to_response('polls/redirect.html', dct) return response