简体   繁体   中英

Django ratelimit custom function

how can I put a custom function for the method in django-ratelimit. I want it to be like this:

I filled out a form.

Then check if the length of the name is less than 5. If the length of the name is less than 5 then as many times as we fill the form it will never block the user. But if the length is bigger every time then the limiter will block the user.

this is how you can do it without django-ratelimit

def rate_view(request):
    if request.method is "POST":
         name = request.POST["name"]
             if len(name) < 5:
                 #your logic 'with never block the user'
                 return render(request, "anyapp/any.html")
             elif len(name) > 5:
                 #block your user here
                 return render(request, "anyapp/any.html")
        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM