def home(): # This function is executed when http://example.com/ is requested. It # works with two methods - GET and POST. When URL is submitted via POST # method, then it catches it and show the regarding short URL or regarding # errors. number = number_of_generated_short_url() if request.method == 'POST': form = GetLinkForm(request.form) if form.validate(): long_url = form.long_url.data checker = url_checker(long_url) if checker is True: short_url = short_url_generator(long_url) return render_template('index.html', form=form, short_url=short_url, number=number) else: flash("The URL seems to be dead at this moment.") return render_template('index.html', form=form, number=number) else: flash("Please, paste a valid link to shorten it.") return render_template('index.html', form=form, number=number) else: return render_template('index.html', form=GetLinkForm(), number=number)
def home(): # This function is executed when http://example.com/ is requested. It # works with two methods - GET and POST. When URL is submitted via POST # method, then it catches it and show the regarding short URL or regarding # errors. number = number_of_generated_short_url() if request.method == "POST": form = GetLinkForm(request.form) if form.validate(): long_url = form.long_url.data checker = url_checker(long_url) if checker is True: short_url = short_url_generator(long_url) return render_template("index.html", form=form, short_url=short_url, number=number) else: flash("The URL seems to be dead at this moment.") return render_template("index.html", form=form, number=number) else: flash("Please, paste a valid link to shorten it.") return render_template("index.html", form=form, number=number) else: return render_template("index.html", form=GetLinkForm(), number=number)
def page_not_found(error): # This function handles all 404 error on the app and shows a custom 404 # error page. number = number_of_generated_short_url() return render_template('404.html', number=number), 404
def page_not_found(error): # This function handles all 404 error on the app and shows a custom 404 # error page. number = number_of_generated_short_url() return render_template("404.html", number=number), 404