Main entry point for a request-response process.
(cls, **initkwargs)
| 116 | # See: https://code.djangoproject.com/ticket/15668 |
| 117 | @classonlymethod |
| 118 | def as_view(cls, **initkwargs): |
| 119 | """ |
| 120 | Main entry point for a request-response process. |
| 121 | """ |
| 122 | # sanitize keyword arguments |
| 123 | for key in initkwargs: |
| 124 | if key in cls.http_method_names: |
| 125 | raise TypeError("You tried to pass in the %s method name as a " |
| 126 | "keyword argument to %s(). Don't do that." |
| 127 | % (key, cls.__name__)) |
| 128 | if not hasattr(cls, key): |
| 129 | raise TypeError("%s() received an invalid keyword %r" % ( |
| 130 | cls.__name__, key)) |
| 131 | |
| 132 | def view(request, *args, **kwargs): |
| 133 | self = cls(**initkwargs) |
| 134 | if hasattr(self, 'get') and not hasattr(self, 'head'): |
| 135 | self.head = self.get |
| 136 | return self.dispatch(request, *args, **kwargs) |
| 137 | |
| 138 | # take name and docstring from class |
| 139 | update_wrapper(view, cls, updated=()) |
| 140 | |
| 141 | # and possible attributes set by decorators |
| 142 | # like csrf_exempt from dispatch |
| 143 | update_wrapper(view, cls.dispatch, assigned=()) |
| 144 | return view |
| 145 | |
| 146 | # _allowed_methods only present from 1.5 onwards |
| 147 | def _allowed_methods(self): |