Django signal emitting once, received twice — Why?

后端 未结 2 864
名媛妹妹
名媛妹妹 2021-02-02 14:27

I\'m working with Django signals, but they seem to be received twice, even if emitted once. Here\'s the code I\'m working with (it\'s a simple wrapper to use Uploadify with Dja

相关标签:
2条回答
  • 2021-02-02 14:47

    you can check "created" argument in your function that you are connecting with signal which returns True and False respectively.

    def task_feedback_status_handler(sender, instance, created, **kwargs):
    do something
    post_save.connect(task_feedback_status_handler, sender=Feedback)
    
    0 讨论(0)
  • 2021-02-02 15:00

    This has happened to me before and it was due to the module where you are connecting the signal being imported twice. To make sure the signal isn't connected twice you can set the dispatch_uid:

    upload_recieved.connect(upload_received_handler, dispatch_uid="some.unique.string.id")
    

    UPDATE It is actually documented here: http://code.djangoproject.com/wiki/Signals#Helppost_saveseemstobeemittedtwiceforeachsave

    0 讨论(0)
提交回复
热议问题