Search code examples
djangodjango-signals

I am trying to set up django signals to let someone get noticed after creating a blog


but this code does not work... keep error message like 'TypeError at /blog/create/

Here are the codes I put at 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, )

?? is the problem... I put pk=pk, pk=id, I don't know what parameter I need to put here...


Solution

  • You don't need to explicitly get the Post, you already have it as the instance parameter sent to the signal (as per the docs):

    instance
    The actual instance being saved.