本文整理汇总了Python中blog.models.Blog.blog_title方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.blog_title方法的具体用法?Python Blog.blog_title怎么用?Python Blog.blog_title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Blog
的用法示例。
在下文中一共展示了Blog.blog_title方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_item
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import blog_title [as 别名]
def process_item(self, item, spider):
blog=Blog()
blog.blog_title=item['title']
#blog.blog_text="[%s](%s)"%(item['title'],item['href'])
#处理href,只取最后几位数字
num=item['href'].split('.')[-2][-7:]
blog.blog_text='blog/html/'+num+'.html'
blog.blog_img=''
blog.blog_text_brief=''
blog.pub_date=datetime.datetime.strptime(item['date_str'],'%Y-%m-%d %H:%M')
blog.blog_praise=int(item['commentnum'])
blog.save()
#html=open(blog.blog_text,'w')
#content=item['content']
#html.write(content.encode("gbk"))
#html.close()
html_dir='/home/dk/mysite/blog/templates/'+blog.blog_text
file=open(html_dir,'w')
u=item['content']
file.write(u.encode('utf-8'))#utf8转str
file.close()
return item
示例2: blog_publish
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import blog_title [as 别名]
def blog_publish(request, whose):
"""
发表博客
前台使用的Ajax请求
:param request:请求
:param whose:当前请求用户的唯一标识
:return:
"""
if request.method == 'POST' and request.is_ajax():
try:
blog_title = request.POST['blogTitle']
blog_content = request.POST['blogContent']
category = request.POST['blogCategory']
is_top = request.POST['top']
is_star = request.POST['star']
level = request.POST['level']
key_words = request.POST['keyWords']
status = request.POST['status']
except KeyError:
logger.debug('* 带非法参数请求,已经拒绝用户')
raise Http404
logger.debug('* BLOG TITLE:' + blog_title)
logger.debug('* BLOG CONTENT:' + blog_content)
logger.debug('* BLOG CATALOG:' + category)
logger.debug('* BLOG TOP:' + is_top)
logger.debug('* BLOG STAR:' + is_star)
logger.debug('* BLOG LEVEL:' + level)
logger.debug('* BLOG KEYS:' + key_words)
logger.debug('* STATUS:' + status)
# 使用博文表单验证对表单的合法性做确认
form = BlogPublishForm(request.POST)
user = User.objects.get(login_id=request.session['login_id'])
exist = Blog.objects.filter(user=user, blog_title=blog_title).count() != 0
response = {}
if exist:
response['error'] = 'error'
response['msg'] = '当前博文标题已经存在于您的博客中,请修改标题'
return HttpResponse(json.dumps(response), content_type='application/json')
elif form.is_valid():
logger.debug('* 信息均已经填写完整,通过表单验证,写入数据库')
is_update_op = False
if 'blogId' in request.POST:
logger.debug("* 当前进行的操作是更新博文操作")
is_update_op = True
publish_ip = request.META['REMOTE_ADDR']
print(color_format("* 客户端的IP地址是:{}".format(publish_ip), fore='cyan'))
if is_update_op:
blog = Blog.objects.get(user=user, blog_id=request.POST['blogId'])
blog.update_date = datetime.datetime.now()
else:
blog = Blog()
# 设值博文的标题
blog.blog_title = blog_title
# 设值博文发表的内容
blog.blog_content = blog_content
# 设置博文发表者的IP
blog.publish_ip = publish_ip
# 设置博文的分类
blog.category = BlogCategory.objects.filter(user=user, category_id=category).first()
blog.keywords = key_words
blog.level = level
blog.star = is_star == 'true'
blog.top = is_top == 'true'
blog.status = status
blog.user_id = user.user_id
blog.save()
response['error'] = 'success'
response['msg'] = '博客进入审核阶段,审核合法后发表'
else:
logger.debug('* 博客内容不完整')
response['error'] = 'error'
response['msg'] = '博客内容不完整'
return HttpResponse(json.dumps(response), content_type='application/json')
else:
logger.debug('* 非法请求方式,已经拒绝用户')
raise Http404