user6307062
user6307062

Reputation:

post() takes exactly 1 argument (2 given) django

I've been coding this, so i wanted to create like a forum, and this is the comments part, if you guys can help me i will be really thankfull.

views.py

class createComment(View):
    form_class = CommentForm
    template_name = "createComment.html"

    def get(self, request):
        form = self.form_class(None)
        return render(request, self.template_name, {'form':form})

    def post(request):
        try:
            if request.method == "POST":
                form = createComment()
                if form.is_valid():
                    obj = form.save(commit=False)
                    obj.user_comment = request.user
                    obj.body_comment = request.POST["body_comment"]
                    obj.post_comment = request.POST[id]
                    obj.status_comment = False
                    obj.save()
                    return redirect('/')
            else:
                form = createComment()
        except Exception, e:
            return render_to_response("errorTemplate.html", {"message" : e.message})

        return redirect('/')

models.py

class Comment(models.Model):
    user_comment = models.ForeignKey("auth.User")
    body_comment = models.TextField()
    timestamp_comment = models.DateTimeField(auto_now=True)
    post_comment = models.ForeignKey("Post", null=True)
    status_comment = models.BooleanField()

    def __unicode__(self):
        return unicode(self.user_comment)

    def __str__(self):
        return self.title_comment

Upvotes: 1

Views: 1545

Answers (1)

Alex Hall
Alex Hall

Reputation: 36043

def get(self, request):
    ...

def post(request):
    ...

You forgot the self argument.

Upvotes: 3

Related Questions