Home >  > django源码

django源码

0

一、获取用户IP

remote_addr = request.META.get(´REMOTE_ADDR´)

二、控制用户每分钟访问次数的代码:

import time
VISIT_RECORD = {}

remote_addr = request.META.get(´REMOTE_ADDR´)
ctime = time.time()
if remote_addr not in VISIT_RECORD:
    VISIT_RECORD(remote_addr) = [ctime,]
    return True
history = VISIT_RECORD.get(remote_addr)

while history and history[-1]<ctime-60:
    history.pop()

if len(history) < 3:
   history.insert(0,ctime)
   return True

129-14 未ok

https://www.bilibili.com/video/av28871471/?p=27

本文暂无标签

发表评论

*

*