def shorten(): long_url = request.args.get("url") if not long_url: raise BadRequest() url_model = Url.shorten(long_url) short_url = "/".join([request.host, url_model.short_url]) return render_template("success.html", short_url=short_url)
def shorten(): """Returns short_url of requested full_url.""" # Validate user input full_url = request.args.get('url') if not full_url: raise BadRequest() # Model returns object with short_url property url_model = Url.shorten(full_url) short_url = request.host + '/' + url_model.short_url return render_template('success.html', short_url=short_url)
def add_url(): long_url = request.form['long_url'] short_url = request.form['short_url'] new_url = Url() short_url = new_url.shorten(long_url, short_url) return redirect(url_for('info_page', short_url=short_url))