示例#1
0
def redirect_to_long(path=""):
    url_model = Url.get_by_short_url(path)

    if not url_model:
        raise NotFound()

    return redirect(url_model.long_url)
def redirect_to_full(path=''):
    """Gets short url and redirects user to corresponding full url if found"""
    # Model returns object with full_url property
    url_model = Url.get_by_short_url(path)
    print(url_model)
    print(url_model.full_url)
    # Validate model return
    if not url_model:
        raise NotFound()
    if not url_model.full_url.startswith('http'):
        url_model.full_url = 'http://' + url_model.full_url
        print(url_model.full_url)
    return redirect(url_model.full_url)