📜  DRF:获取 IP 地址 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:26.916000             🧑  作者: Mango

代码示例1
from rest_framework import permissions

class BlocklistPermission(permissions.BasePermission):
    """
    Global permission check for blocked IPs.
    """

    def has_permission(self, request, view):
        ip_addr = request.META['REMOTE_ADDR']
        blocked = Blocklist.objects.filter(ip_addr=ip_addr).exists()
        return not blocked