本文整理汇总了Python中forum.models.Post.tagnames方法的典型用法代码示例。如果您正苦于以下问题:Python Post.tagnames方法的具体用法?Python Post.tagnames怎么用?Python Post.tagnames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forum.models.Post
的用法示例。
在下文中一共展示了Post.tagnames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_post
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import tagnames [as 别名]
def add_post(request, post_id=None):
if post_id:
post = get_object_or_404(Post, pk=post_id)
if post.author != request.user:
return HttpResponseForbidden("Only owner of this post is allowed to edit")
else:
post = Post(author=request.user)
if request.method == 'POST': # If the form has been submitted...
form = PostForm(request.POST, instance=post) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
text = form.cleaned_data['content']
html = markdown(text)
post.title = form.cleaned_data['title']
post.content = html
post.tagnames = form.cleaned_data['tagnames']
post.save()
return HttpResponseRedirect('/')
else:
# An unbound form
form = PostForm(instance=post)
return render(request, 'new_post.html', {
'form': form,
'post_id': post_id,
})