本文整理汇总了Python中models.Url.url方法的典型用法代码示例。如果您正苦于以下问题:Python Url.url方法的具体用法?Python Url.url怎么用?Python Url.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Url
的用法示例。
在下文中一共展示了Url.url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import url [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: make_url_model
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import url [as 别名]
def make_url_model(url, site):
""" This should on occur once per newly created URL, the linked count is set to zero if it
is a new site added to database
"""
now = datetime.now()
base_url = 'http://links.ep.io/'
url_model = Url()
url_model.url = url
url_short = url
try:
domain = Domain.objects.get(site=site)
domain.linked_count += 1
domain.date_updated = now
domain.save()
except:
domain = Domain(site=site, linked_count=1, date_updated= now)
domain.save()
url_model.site = domain
url_model.date_time_created = datetime.now()
url_model.linked_count = 1
url_model.save()
url_model.url_shortened = base_url + encode_62(url_model.pk)
print url_model.url_shortened
url_model.save()
return url_model