当前位置: 首页>>代码示例>>Python>>正文


Python Url.url方法代码示例

本文整理汇总了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')
开发者ID:nickpegg,项目名称:shrtnr,代码行数:33,代码来源:shrtnr.py

示例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
开发者ID:myusuf3,项目名称:links,代码行数:27,代码来源:views.py


注:本文中的models.Url.url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。