本文整理匯總了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,
})