2017-09-22 34 views

回答

1

檢查您的功能請求是否是POSTGET。如果是帖子,您可以檢查用戶的憑據以驗證他們是否是超級用戶。

def list(self, request): 
    if request.method == 'POST': 
     if request.user.is_superuser: 
      # let superuser do their thing 
     else: 
      # error! you're not allowed to do this! 
    elif request.method == 'GET': 
     # you're any user who is allowed to do their thing 
相關問題