python - How to do log review under Django
高洛峰
高洛峰 2017-05-18 10:59:11
0
2
790

Under the existing system, a log audit needs to be added.

Existing environment: Django Mongodb.

Then I want to use logging directly to process logs, but how to store them in the database?

I saw some people discussing signals processing on the Internet. I am not very familiar with this block. I would like to ask if it is okay to only process views, because the existing environment does not have the processing of models. Thanks

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
Peter_Zhu

Write a decorator? If model is not used

黄舟

If you want to record changes in models, it is recommended to use django-reversion.

Update:

You can redirect the user to the view you use to record the user's login time, IP, and username after logging in. Then redirect to another view.

from ipware.ip import get_ip
import datetime

class UserLoginLogView(View, LoginRequiredMixin):


    def get(self, request, pk):
        ip = get_ip(request)
        user = self.request.user
        time = datetime.datetime.now()
        url = reverse(home)
        login_log = UserLoginLogModel.objects.create(user=user, ip=ip, time=time)
        return HttpResponseRedirect(url)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template