本文整理汇总了Python中models.Url.get方法的典型用法代码示例。如果您正苦于以下问题:Python Url.get方法的具体用法?Python Url.get怎么用?Python Url.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Url
的用法示例。
在下文中一共展示了Url.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import get [as 别名]
def index():
if request.method == 'POST':
thing = request.form.get('url')
if thing:
if '://' not in thing:
thing = 'http://' + thing
# Verify the URL
parsed = urlparse(thing)
if parsed.scheme not in ('http', 'https'):
return "I only take HTTP or HTTPS URLs, dummy"
urlhash = hashlib.sha1(thing).hexdigest()
try:
url = Url.get(Url.url_hash == urlhash)
except:
url = Url()
url.url = thing
url.url_hash = urlhash
url.created = datetime.datetime.now()
url.save()
# hokay. got us an ID, let's make a key.
url.key = base36_encode(url.id)
url.save()
return render_template('added.html', short_url="http://{0}/{1}".format(request.headers['host'], url.key))
else:
return "You didn't give me shit"
else:
return render_template('index.html')
示例2: go
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import get [as 别名]
def go(key):
result = "There's no URL with that key, dummy!"
try:
url = Url.get(Url.key == key)
if url.enabled:
result = redirect(url.url)
except:
pass
return result