我正在尝试设置 django 信号,让某人在创建博客后受到关注
I am trying to set up django signals to let someone get noticed after creating a blog
但此代码不起作用...在 /blog/create/
保留类似“TypeError”的错误消息
这是我放在 blog/signals.py
的代码
@receiver(signals.post_save, sender=Post)
def send_mail(sender, instance, created, **kwargs):
print('signal send')
subject = "Thank you"
message = Post.objects.get(??)
send_mail(subject, 'message', '',
['info@*****.com.au'], fail_silently=False, )
??是这个问题...我放pk=pk,pk=id,不知道这里需要放什么参数...
您不需要显式获取 Post
,您已经将其作为发送到信号的 instance
参数(根据 docs):
instance
The actual instance being saved.
但此代码不起作用...在 /blog/create/
保留类似“TypeError”的错误消息这是我放在 blog/signals.py
的代码@receiver(signals.post_save, sender=Post)
def send_mail(sender, instance, created, **kwargs):
print('signal send')
subject = "Thank you"
message = Post.objects.get(??)
send_mail(subject, 'message', '',
['info@*****.com.au'], fail_silently=False, )
??是这个问题...我放pk=pk,pk=id,不知道这里需要放什么参数...
您不需要显式获取 Post
,您已经将其作为发送到信号的 instance
参数(根据 docs):
instance
The actual instance being saved.