Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 根据用户组限制用户_Python_Django_Django Rest Framework - Fatal编程技术网

Python 根据用户组限制用户

Python 根据用户组限制用户,python,django,django-rest-framework,Python,Django,Django Rest Framework,我想根据Saas应用程序的用户组限制用户的表单请求(免费、付费),因此,如果免费用户达到限制,他们将被重定向到另一个页面或显示弹出窗口 我尝试使用节流,但我不知道如何实现这些条件 设置.py REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.BasicAuthentication', 'r

我想根据Saas应用程序的用户组限制用户的表单请求(免费、付费),因此,如果免费用户达到限制,他们将被重定向到另一个页面或显示弹出窗口

我尝试使用节流,但我不知道如何实现这些条件

设置.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.BasicAuthentication',
                                        'rest_framework.authentication.TokenAuthentication'],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated'
    ],
    'DEFAULT_THROTTLE_CLASSES': [
        'rest_framework.throttling.UserRateThrottle',
        'contact.throttling.FreeDailyRateThrottle'
    ],
    'DEFAULT_THROTTLE_RATES': {
        'user': '5/second',
        'Free': '200/day'
    }
}
views.py

class FreeDailyRateThrottle(UserRateThrottle):
    scope = 'Free'
    user = request.user
    if user.groups.filter(name=Free).exists() :
        #i'm not sure what to do here!
    else :
        #redirect to a different page



@login_required(login_url='login')
@api_view(['POST'])
@throttle_classes([FreeDailyRateThrottle])
def ad_gen(request):

    context ={}

    if request.method!="POST":
        return render(request , 'Ad Gen.html' , context)

    else:
         // some logic
        return render(request , 'Ad result.html' ,context)