Get current user log in signal in Django

后端 未结 6 1765
忘掉有多难
忘掉有多难 2021-02-05 10:01

I am just using the admin site in Django. I have 2 Django signals (pre_save and post_save). I would like to have the username of the current user. How would I do that? It does n

6条回答
  •  执念已碎
    2021-02-05 10:20

    In both signals, signal send three arguments,

    • Sender
    • Instance
    • Using

    What you need is the Instant being modified...

    def signal_catcher(sender, instance, **kwargs):
        uname = instance.username
    

    http://docs.djangoproject.com/en/dev/ref/signals/#pre-save

提交回复
热议问题