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