from django.shortcuts import render, get_object_or_404, redirect, reverse
from django.views.generic import View
# Create your views here.
from django.http import HttpResponse
from .models import Comment
from blogs.models import Article
from .forms import CommentForm


class AddComment(View):
    def post(self, request, id):
        article = get_object_or_404(Article, pk=id)

        cf = CommentForm(request.POST)
        if cf.is_valid():
            username = cf.cleaned_data['name']

            email = cf.cleaned_data['email']

            url = cf.cleaned_data['url']

            comment = cf.cleaned_data['comment']

            c=Comment()
            c.username=username
            c.email=email
            c.url=url
            c.content = comment
            c.article = article
            c.save()
            return redirect(reverse('blogs:detail',args=(id,)))
        else:
            return HttpResponse("输入不合法")



























55956eba8b8d1e31912c95d0381b8d3ac6370dfe
<mask token>

<mask token>


class AddComment(View):
    <mask token>

<mask token>


class AddComment(View):

    def post(self, request, id):
        article = get_object_or_404(Article, pk=id)
        cf = CommentForm(request.POST)
        if cf.is_valid():
            username = cf.cleaned_data['name']
            email = cf.cleaned_data['email']
            url = cf.cleaned_data['url']
            comment = cf.cleaned_data['comment']
            c = Comment()
            c.username = username
            c.email = email
            c.url = url
            c.content = comment
            c.article = article
            c.save()
            return redirect(reverse('blogs:detail', args=(id,)))
        else:
            return HttpResponse('输入不合法')

from django.shortcuts import render, get_object_or_404, redirect, reverse
from django.views.generic import View
from django.http import HttpResponse
from .models import Comment
from blogs.models import Article
from .forms import CommentForm


class AddComment(View):

    def post(self, request, id):
        article = get_object_or_404(Article, pk=id)
        cf = CommentForm(request.POST)
        if cf.is_valid():
            username = cf.cleaned_data['name']
            email = cf.cleaned_data['email']
            url = cf.cleaned_data['url']
            comment = cf.cleaned_data['comment']
            c = Comment()
            c.username = username
            c.email = email
            c.url = url
            c.content = comment
            c.article = article
            c.save()
            return redirect(reverse('blogs:detail', args=(id,)))
        else:
            return HttpResponse('输入不合法')

from django.shortcuts import render, get_object_or_404, redirect, reverse
from django.views.generic import View
# Create your views here.
from django.http import HttpResponse
from .models import Comment
from blogs.models import Article
from .forms import CommentForm


class AddComment(View):
    def post(self, request, id):
        article = get_object_or_404(Article, pk=id)

        cf = CommentForm(request.POST)
        if cf.is_valid():
            username = cf.cleaned_data['name']

            email = cf.cleaned_data['email']

            url = cf.cleaned_data['url']

            comment = cf.cleaned_data['comment']

            c=Comment()
            c.username=username
            c.email=email
            c.url=url
            c.content = comment
            c.article = article
            c.save()
            return redirect(reverse('blogs:detail',args=(id,)))
        else:
            return HttpResponse("输入不合法")


























