Callable Class View

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
class View(object):
    def __new__(cls, request, **kwargs):
        obj = super(View, cls).__new__(cls)
        return obj(request, **kwargs)
    
    def __init__(self):
        pass
        
    def __call__(self, request, **kwargs):
        pass

class GetPostView(View):
    def __call__(self, request, **kwargs):
        if request.POST:
            return self.Post(request, **kwargs)
        return self.Get(request, **kwargs)
    
    def Get(self, request, **kwargs):
        pass
        
    def Post(self, request, **kwargs):
        pass

More like this

  1. Callable object as signal receiver by diverman 5 years ago
  2. Ajax API class by kcarnold 5 years, 10 months ago
  3. Language aware cache decorator by bartTC 4 years, 12 months ago
  4. Resource by zvoase 5 years, 7 months ago
  5. My approach on class based views by henning 3 years, 10 months ago

Comments

mike_45 (on February 3, 2009):

Nice. Just what the doctor ordered.

#

(Forgotten your password?)