当前位置: 首页>>代码示例>>Python>>正文


Python Comment.comment方法代码示例

本文整理汇总了Python中blog.models.Comment.comment方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.comment方法的具体用法?Python Comment.comment怎么用?Python Comment.comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blog.models.Comment的用法示例。


在下文中一共展示了Comment.comment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_article

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import comment [as 别名]
def get_article(request,slug):
    try:
        article=Article.objects.get(slug=slug)
    except ObjectDoesNotExist:
        return HttpResponseRedirect('/')

    try:
        comments=Comment.objects.filter(article=article).order_by('-date','-id')        
    except ObjectDoesNotExist:
        comments=None
   
    if request.method == 'POST': 
        form = CommentForm(request.POST, **{'article':article,'ip':request.META['REMOTE_ADDR'],})
        if form.is_valid(): 
            comment=Comment()
            comment.comment = form.cleaned_data['comment']
            comment.article = article
            if request.user.is_authenticated():
                comment.user = request.user
            comment.ip=request.META['REMOTE_ADDR']
            comment.save()
            return HttpResponseRedirect('/'+article.slug) 
    else:
        form = CommentForm() 

    
    return render_to_response('blog/article.html', {
        'form': form,
        'article': article,
        'comments':comments,
    },context_instance=RequestContext(request))
开发者ID:glebkolyagin,项目名称:superblog,代码行数:33,代码来源:views.py

示例2: comment

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import comment [as 别名]
def comment(request, id):
    """
    Add a comment to blog
    """
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            comment = Comment()
            comment.comment = data['comment']
            comment.blog_id = id
            comment.user_name = data['user_name']
            comment.email = data['email']
            comment.source_address = request.META['REMOTE_ADDR']# '192.168.2.8'
            comment.create_date = datetime.datetime.now()
            comment.save()
            blog = Blog.objects.get(id=id)
            if blog.comment_count is None:
                blog.comment_count = 0
            blog.comment_count += 1
            blog.save()
            if request.user.is_authenticated():
                return HttpResponseRedirect('/adminshow/%s/' % id)
            else:
                return HttpResponseRedirect('/show/%s/' % id)
        else:
            blog = Blog.objects.get(id=id)
            comments = Comment.objects.filter(blog_id=id)
            return render_to_response('artical.html', {'blog' : blog, 'comments' : comments, 'form' : form}, context_instance=RequestContext(request, processors=[new_blog, blog_group]))
    else:
        return HttpResponseRedirect('/show/%s/' % id)
开发者ID:kelvinfang,项目名称:juncheefamily,代码行数:33,代码来源:views.py

示例3: post

# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import comment [as 别名]
 def post(self, request, *args, **kwargs):
     comment_form = CommentForm(data=request.POST)
     if comment_form.is_valid():
         comment = Comment()
         comment.author = request.user
         comment.comment = comment_form.cleaned_data['comment']
         comment.post = self.get_post(**kwargs)
         comment.save()
         return self.get(request, *args, **kwargs)
     else:
         return self.get(request, *args, **kwargs)
开发者ID:DheerendraRathor,项目名称:idc,代码行数:13,代码来源:views.py


注:本文中的blog.models.Comment.comment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。