本文整理汇总了Python中models.Url.get_by_short_url方法的典型用法代码示例。如果您正苦于以下问题:Python Url.get_by_short_url方法的具体用法?Python Url.get_by_short_url怎么用?Python Url.get_by_short_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Url
的用法示例。
在下文中一共展示了Url.get_by_short_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: redirect_to_long
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import get_by_short_url [as 别名]
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)
示例2: redirect_to_full
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import get_by_short_url [as 别名]
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)