我的代码在哪里包含问题?我不明白 现在,我看不到属于url以下的渲染模板。 我看到这个错误 Message()得到了意外的关键字参数'initial'
class Message(models.Model):
sender = models.ForeignKey(CustomUser, related_name = 'message_sender', on_delete = models.CASCADE)
reciever = models.ForeignKey(CustomUser, related_name = 'message_reciever', on_delete = models.CASCADE)
message = models.TextField()
def __str__(self):
return f'{self.message}'
def get_url(self):
return reverse('profile', args = [str(self.sender.pk)])
class SendMessageView(CreateView):
form_class = Message
template_name = 'send_message.html'
path('<int:pk>/send', SendMessageView.as_view(), name = 'send_message'),
答案 0 :(得分:2)
您必须将 form_class 替换为 model
class SendMessageView(CreateView):
model = Message
fields = '__all__'
template_name = 'send_message.html'
您可以在 more
获得更多信息