django源码

Django 6 浏览 1 分钟阅读

一、获取用户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

0

  1. This post has no comment yet

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

相关文章