本文整理汇总了Python中models.Url.fill_title方法的典型用法代码示例。如果您正苦于以下问题:Python Url.fill_title方法的具体用法?Python Url.fill_title怎么用?Python Url.fill_title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Url
的用法示例。
在下文中一共展示了Url.fill_title方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import fill_title [as 别名]
def index(request, tag=None):
if tag:
tag_model = get_object_or_404(Tag, name=tag)
urls = tag_model.url_set.all()
else:
urls = Url.objects.all()
if request.method == "POST":
form = UrlForm(request.POST)
if form.is_valid():
url_data = form.cleaned_data['url']
title = form.cleaned_data['title']
tags = form.cleaned_data['tags']
try:
url = Url(url=url_data, title=title)
url.fill_title()
url.save()
url.add_tags_from_string(tags)
if tag:
url.add_tag(tag)
except IntegrityError:
pass
return HttpResponseRedirect(request.path)
else:
form = UrlForm()
return render_to_response("index.html", {
'urls': urls,
'form': form,
})
示例2: test_get_url_with_no_title
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import fill_title [as 别名]
def test_get_url_with_no_title(self):
response = self.mocker.mock()
response.read()
self.mocker.result("foo.zip")
urlopen = self.mocker.replace("urllib.urlopen")
urlopen("http://example.com/foo.zip")
self.mocker.result(response)
self.mocker.replay()
url = Url(url="http://example.com/foo.zip")
url.fill_title()
self.assertEquals(url.title, "")
示例3: test_fill_title_does_not_override_title
# 需要导入模块: from models import Url [as 别名]
# 或者: from models.Url import fill_title [as 别名]
def test_fill_title_does_not_override_title(self):
response = self.mocker.mock()
response.read()
self.mocker.result("""
<html>
<head>
<title>Example Web Page</title>
</head>
</html>
""")
urlopen = self.mocker.replace("urllib.urlopen")
urlopen("http://example.com")
self.mocker.result(response)
self.mocker.replay()
url = Url(url="http://example.com", title="My Title")
url.fill_title()
self.assertEquals(url.title, "My Title")