本文整理汇总了Python中blog.models.Blog.title方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.title方法的具体用法?Python Blog.title怎么用?Python Blog.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Blog
的用法示例。
在下文中一共展示了Blog.title方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_mysql
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def to_mysql(req):
path = r'{0}/templates'.format(os.path.dirname(__file__))
num = len(sum([i[2] for i in os.walk(path)], [])) - 1
id = 1
for i in range(num):
url = "{0}/templates/{1}.html".format(os.path.dirname(__file__), id)
#url = "blog/templates/1.html"
try:
soup = BeautifulSoup(open(url, encoding="UTF-8"))
if len(soup):
categorie = soup.find(id='categorie').string
blog_id = id
title = soup.find(id='blog_title').string
post_time = str(soup.find(id='blog_post_time'))[35:45]
blog = Blog()
blog.blog_id = blog_id
blog.title = title
blog.post_time = post_time
blog.categorie = categorie
blog.save()
else:
break
except Exception as e:
error_log.error(e)
finally:
id += 1
return HttpResponse("<div style='text-align:center;'>{0} - To-Mysql-Done</div>".format(id))
示例2: newPost
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def newPost(self, blogid, username, password, struct, publish):
self.__isUser(username, password)
# print(("blogid:", blogid))
# print(("struct:", struct))
title = struct['title']
content = struct['description']
categorie = struct['categories'][0]
#生成静态HTML文件
id = None
try:
path = r'{0}/templates'.format(os.path.dirname(__file__))
id = len(sum([i[2] for i in os.walk(path)], []))
# print("博客ID:", id)
static(id, content, categorie, title)
blog = Blog()
blog.blog_id = id
blog.title = title
blog.categorie = categorie
blog.content = content
blog.summary = get_summary(content, 150, u'...')
blog.post_time = datetime.datetime.today()
blog.save()
except Exception as e:
error_log.error("生成静态文件失败:{0}".format(e))
return id
示例3: create_blog
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def create_blog(request):
errors = []
template = "blog/templates/create_blog.html"
form = CreateBlogForm()
user = request.user
if not user.is_authenticated():
raise Http404
if request.method == "POST":
form = CreateBlogForm(request.POST)
if form.is_valid():
try:
data = form.cleaned_data
_blog = Blog()
_blog.title = data["title"]
_blog.owner = user
_blog.url = data["url"]
_blog.tagline = data["tagline"]
_blog.active = True
_blog.save()
_blog.contributors.add(user)
_blog.save()
return HttpResponseRedirect("/blog/%s/"%user.username)
except:
errors.append("Blog URL already taken.")
return render(request, template, {"errors":errors, "form":form})
示例4: post
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def post(self, request):
"""
Crea un user en base a la información POST
:param request: HttpRequest
:return: HttpResponse
"""
success_message = ''
form = SignupForm(request.POST)
if form.is_valid():
user = User()
user.username = form.cleaned_data.get('usr')
user.first_name = form.cleaned_data.get('first_name')
user.last_name = form.cleaned_data.get('last_name')
user.email = form.cleaned_data.get('email')
user.set_password(form.cleaned_data.get('password'))
user.save()
blog = Blog()
blog.title = "My first blog"
blog.owner = user
blog.save()
success_message = 'Creado con éxito!'
success_message += '<a href="{0}">'.format(
reverse('post_home', args=[])
)
success_message += 'go Home!'
success_message += '</a>'
context = {
'form': form,
'success_message': success_message
}
return render(request, 'users/new_user.html', context)
示例5: createBlog
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def createBlog(user):
blog=Blog()
blog.user_id=user.id
blog.title=user.username+"的博客".decode("utf-8")
blog.modules="profile,hotarticlelist,hotcommentlist"
blog.template="default"
blog.createtime=datetime.datetime.now()
blog.save()
示例6: create
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def create(request):
if request.method == "GET":
return render(request,'blog/create.html',{})
new_blog = Blog()
new_blog.title = request.POST["title"]
new_blog.text = request.POST["text"]
new_blog.save()
return redirect('blog_id',new_blog.id)
示例7: form_valid
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def form_valid(self, form):
if hasattr(self.request.user, 'blog'):
form.instance.blog = self.request.user.blog
else:
if 'create' in self.request.POST:
blog = Blog()
blog.author = self.request.user
blog.title = self.request.user.get_full_name()
blog.save()
form.instance.blog = blog
return super(PostCreateView, self).form_valid(form)
示例8: post
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def post(self, request):
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
new_user = serializer.save()
blog = Blog()
blog.title = request.data.get("blog")
blog.owner = new_user
blog.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例9: addblogok
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def addblogok(request):
title=request.POST.get('title')
tag_ids=request.POST.getlist('tag_name')
content=request.POST.get('content')
blog=Blog()
blog.title=title
blog.content=content
blog.save()
for tag_id in tag_ids:
list=Tag.objects.get(id=int(tag_id))
blog.tags.add(list)
return HttpResponseRedirect('/list/')
示例10: post
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def post(self):
self._form = AddBlogForm(request.form)
if self._form.validate():
from blog.models import Blog
blog = Blog()
blog.name = self._form.name.data
blog.date_added = self._form.date_added.data
blog.title = self._form.title.data
blog.slug = self._form.slug.data
author_id = self._form.author_id.data
category = self._form.category.data
blog.save()
return self.redirect('blog.list')
示例11: create
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def create(request):
if request.method == 'POST':
blog = Blog()
blog.title = request.POST.get('title')
blog.content = request.POST.get('content')
greeting.isprivate = request.POST.get('isprivate')
if greeting.isprivate == None:
greeting.isprivate = 0
greeting.isprivate = request.POST.get('isprivate')
if greeting.isprivate == None:
greeting.isprivate = 0
try:
user_id = request.session['user_id']
greeting.save()
except KeyError:
greeting.author = 'anonymous'
greeting.save()
return HttpResponseRedirect('/greeting/')
示例12: new
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import title [as 别名]
def new(request):
"""
Add a new blog
"""
if request.method == 'POST':
form = BlogForm(request.POST)
if form.is_valid():
data = form.cleaned_data
blog = Blog()
blog.group = data['group']
blog.status = data['status']
blog.title = data['title']
blog.tag = data['tag']
blog.content = data['content']
blog.summary = data['summary']
blog.access_count = 0
blog.comment_count = 0
blog.create_date = datetime.datetime.now()
blog.update_date = datetime.datetime.now()
blog.save()
return HttpResponseRedirect('/adminshow/%s' % blog.id)
else:
form = BlogForm()
return render_to_response('new.html', {'form':form}, context_instance=RequestContext(request, processors=[new_blog, blog_group]))