[英]Django run function on logging out of admin page
I'm trying to find a way to handle on admin logout (django admin page), files in a certain folder will get deleted.我正在尝试找到一种处理管理员注销(django 管理页面)的方法,某个文件夹中的文件将被删除。 Because i have a function on certain admin interactions, files will get saved to a folder and i would like these files to get deleted when the admin logging out of the admin page.因为我对某些管理员交互有一个功能,文件将被保存到一个文件夹中,我希望这些文件在管理员退出管理页面时被删除。
I only know about Django detect user logout on browser close like so:我只知道 Django 在浏览器关闭时检测用户注销,如下所示:
if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE:
What i would like to do is to override the logout function of admin site to execute a function and delete files in a folder.我想做的是覆盖管理站点的注销功能以执行功能并删除文件夹中的文件。 I can see that the logout function exists in https://github.com/django/django/blob/master/django/contrib/admin/sites.py#L349 but how do i override it and add my delete files function into it ?我可以看到注销功能存在于https://github.com/django/django/blob/master/django/contrib/admin/sites.py#L349但我如何覆盖它并将我的删除文件功能添加到其中?
If you want to override the logout
function itself, you'll have to subclass the AdminSite
class and create your own class with overriding implementation of logout.如果您想覆盖logout
功能本身,则必须子类化AdminSite
类并使用覆盖注销的实现创建自己的类。
Check this for how to customize AdminSite: How to use custom AdminSite class?检查如何自定义 AdminSite: 如何使用自定义 AdminSite 类?
You can also use the logout signal to run addition functions after user logout.您还可以使用注销信号在用户注销后运行附加功能。
Check: https://docs.djangoproject.com/en/dev/ref/contrib/auth/#module-django.contrib.auth.signals检查: https : //docs.djangoproject.com/en/dev/ref/contrib/auth/#module-django.contrib.auth.signals
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.