class ClassView(View): @use_params_class_view({ 'a': params.Field(required=True), }) def get(self, request): assert request.params.a == '1' return HttpResponse(str(request.params))
class PostJsonHandler(BaseHandler): @use_params( { 'a': params.IntegerField(required=True), 'b': params.Field(), }, is_json=True) def post(self): print('params', self.params) if self.params.a != 1: raise params.InvalidParams('a != 1') if self.params.b and self.params.b != 'b': raise params.InvalidParams('b != b') return self.write(str(self.params))
class PostParams(params.ParamSet): a = params.IntegerField(required=True) b = params.Field()
# coding: utf-8 from django.http import HttpResponse from django.views.generic import View import params from params.contrib.django import use_params, use_params_class_view def index(request): return HttpResponse(request.method) @use_params({ 'a': params.Field(required=True), 'b': params.ListField(), }) def funcview(request): assert request.params.a == '1' assert request.params.b == [u'x', u'y'] return HttpResponse(str(request.params)) class ClassView(View): @use_params_class_view({ 'a': params.Field(required=True), }) def get(self, request): assert request.params.a == '1' return HttpResponse(str(request.params))
class DemoParams(params.ParamSet): a = params.Field()
class DemoParams(params.ParamSet): a_b = params.Field(key='a-b')
class DemoParams(params.ParamSet): a = params.Field(null=False) def validate_a(self, value): pass
class DemoHandler(RequestHandler): @use_params({ 'a': params.Field(), }) def wtf(self): pass
class FooParams(params.ParamSet): bar = params.WordField(choices=['a', 'b', 'c']) quz = params.Field()