def make(request): if request.method == 'POST': url = request.POST.get('url') shortened = request.POST.get('shortened') try: shortened_url = ShortenedURL.objects.get(shortened=shortened) if shortened_url: return HttpResponseRedirect('/exists/') else: new_shortened_url = ShortenedURL(shortened=shortened, url=url) new_shortened_url.save() return HttpResponseRedirect('/success/') except: new_shortened_url = ShortenedURL(shortened=shortened, url=url) new_shortened_url.save() return HttpResponseRedirect('/success/'+shortened) else: form = CreateForm() context = {'form': form} return render(request, 'make.html', context)
def assigner(): payload = request.get_json(force=True) new_SURL = ShortenedURL(src_url = payload["URL"]) db.session.add(new_SURL) db.session.commit() return jsonify(new_SURL.to_dict())