本文整理汇总了Python中models.Blog.content方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.content方法的具体用法?Python Blog.content怎么用?Python Blog.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Blog
的用法示例。
在下文中一共展示了Blog.content方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import content [as 别名]
def new(request):
blog = Blog()
blog.title = 'This is a brand new blog.'
blog.content = 'lalalallalalalalala'
blog.created_at = datetime.datetime.now()
blog.save()
return HttpResponse('Save OK. <a href="/blog/view/%s/">view</a>'%blog.id)
示例2: create
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import content [as 别名]
def create(request):
if not admin():
return HttpResponseRedirect(users.create_login_url("/blogs"))
form = BlogForm(request.POST)
form.fields["category"].choices = [("", "请选择")] + [(category.key(), category.name) for category in Category.all()]
if form.is_valid():
blog = Blog()
blog.title = form.cleaned_data["title"]
blog.content = form.cleaned_data["content"]
if form.cleaned_data["category"]:
blog.category = Category.get(form.cleaned_data["category"])
elif form.cleaned_data["user_tag"]:
blog.category = Category.get_or_insert(form.cleaned_data["user_tag"], name=form.cleaned_data["user_tag"])
blog.create()
return HttpResponseRedirect("/blogs")
else:
return new(request)
示例3: create
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import content [as 别名]
def create(request):
if not admin():
return HttpResponseRedirect(users.create_login_url('/blogs'))
form = BlogForm(request.POST)
form.fields['category'].choices = [('', '请选择')] + [(category.key(), category.name) for category in Category.all()]
if form.is_valid():
blog = Blog()
blog.title = form.cleaned_data['title']
blog.content = form.cleaned_data['content']
if form.cleaned_data['category']:
blog.category = Category.get(form.cleaned_data['category'])
elif form.cleaned_data['user_tag']:
blog.category = Category.get_or_insert(form.cleaned_data['user_tag'], name=form.cleaned_data['user_tag'])
blog.create()
return HttpResponseRedirect('/blogs')
else:
return new(request)
示例4: save_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import content [as 别名]
def save_blog(request):
bid = request.POST.get("bid", "").strip()
title = request.POST.get("title", "").strip()
category = request.POST.get("category", "").strip()
content = request.POST.get("content", "").strip()
if len(title) < 3 or len(content) < 4:
return HttpResponseRedirect("/")
if bid:
try:
bid = int(bid)
# print 'bid: ', bid
except:
# print 'error bid: ', bid
return HttpResponseRedirect("/")
blog_set = Blog.objects.filter(id=bid)
if blog_set:
blog = blog_set[0]
else:
return HttpResponseRedirect("/")
else:
blog = Blog()
blog.tags = "blog"
blog.title = title
blog.content = content
blog.save()
list_category = category.lower().split(",")
for c in list_category:
c = c.strip()
if not c:
continue
cate_set = Category.objects.filter(name=c)
if cate_set:
# print 'category exist: ', c
blog.categorys.add(cate_set[0])
else:
# print 'new category: ', c
_category = Category(name=c)
_category.save()
blog.categorys.add(_category)
return HttpResponseRedirect("/blog/%d.html" % blog.id)
示例5: save_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import content [as 别名]
def save_blog(request):
bid = request.POST.get('bid', '').strip()
title = request.POST.get('title', '').strip()
category= request.POST.get('category', '').strip()
content = request.POST.get('content', '').strip()
print request.POST
if len(title) < 3 or len(content) < 4:
print content
print "title or content not correct"
return HttpResponseRedirect('/')
if bid:
try:
bid = int(bid)
except:
return HttpResponseRedirect('/')
blog_set = Blog.objects.filter(id=bid)
if blog_set:
blog = blog_set[0]
else:
return HttpResponseRedirect('/')
else:
blog = Blog()
blog.tags = 'blog'
blog.title = title
blog.content = content
blog.save()
list_category = category.lower().split(',')
blog.categorys.clear()
for c in list_category:
c = c.strip()
if not c:
continue
cate_set = Category.objects.filter(name=c)
if cate_set:
blog.categorys.add(cate_set[0])
else:
_category = Category(name=c)
_category.save()
blog.categorys.add(_category)
return HttpResponseRedirect('/blog/%d.html'%blog.id)