我想在每次调用POST
请求时调用请求验证器方法。
所以代码我想要:
import validator
class ViewClass():
def __CONSTRUCTOR__(self, request):
is_valid = validator.validate()
if is_valid == FALSE
return HttpResponse('Request is Invalid')
def request_function_one(request):
if request.method == 'POST':
return HttpResponse('Request 1 is Valid')
def request_function_two(request):
if request.method == 'POST':
return HttpResponse('Request 2 is Valid')
如何使用django实现这一目标?
答案 0 :(得分:1)
如果你真的想在django中这样做 - 我建议你看看http://www.django-rest-framework.org/
在这个框架中,你不会因验证者的力量而失望。