小智 19
我发现最简单的事情是继承我正在使用的Authentication类.只需覆盖方法POST时is_authenticated返回True的方法.
class AnonymousPostAuthentication(BasicAuthentication):
""" No auth on post / for user creation """
def is_authenticated(self, request, **kwargs):
""" If POST, don't check auth, otherwise fall back to parent """
if request.method == "POST":
return True
else:
return super(AnonymousPostAuthentication, self).is_authenticated(request, **kwargs)
Run Code Online (Sandbox Code Playgroud)
我把我的验证放在了子类Validation和覆盖中is_valid.
我按照Sampson上面所做的那样进行GET过滤.
| 归档时间: |
|
| 查看次数: |
2552 次 |
| 最近记录: |