gpt4 book ai didi

python - post() 恰好需要 1 个参数(给定 2 个)django

转载 作者:行者123 更新时间:2023-12-01 03:55:23 24 4
gpt4 key购买 nike

我一直在编写这个,所以我想创建一个像论坛一样的东西,这是评论部分,如果你们能帮助我,我将非常感激。

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

最佳答案

def get(self, request):
...

def post(request):
...

您忘记了 self 参数。

关于python - post() 恰好需要 1 个参数(给定 2 个)django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37557058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com