from django.shortcuts import render from django.http import HttpResponse from shortenurl.models import Url # Create your views here. def shortenurl(request): return render(request, 'shorten-url.html') def generateurl(request): errors = [] if 'longurl' in request.GET: longurl = request.GET['longurl'] if not longurl: errors.append('Enter a url') else: url = Url.objects.create(long_url = longurl, short_url = "") id = url.id num = id digits = [] while num > 0: remainder = num%62 digits.append(remainder) num = num/62 digits.reverse() list = getList() shorturl = "www.pooja.com/" for i in digits: shorturl += list[i] url.short_url = shorturl url.save() return render(request, 'displayurl.html', {'shorturl': shorturl, 'longurl' : longurl}) return render(request, 'shorten-url.html', {'errors': errors}) def getList(): list1 = map(chr, range(97, 123)) list2 = map(chr, range(65, 91)) list1 = list1 + list2 list1 = list1 + range(10) return list1
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question