- Author:
- zbyte64
- Posted:
- May 17, 2008
- Language:
- Python
- Version:
- .96
- Tags:
- view callable response
- Score:
- 5 (after 5 ratings)
Instead of using a function for your views, this allows you to use a class. For your urls definition it works just as it normally does.
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
- Serialize a model instance by chriswedgwood 1 week, 1 day ago
- Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 9 months, 1 week ago
- Crispy Form by sourabhsinha396 10 months ago
- ReadOnlySelect by mkoistinen 10 months, 2 weeks ago
- Verify events sent to your webhook endpoints by santos22 11 months, 2 weeks ago
Comments
Nice. Just what the doctor ordered.
#
Please login first before commenting.