# If the request method is HEAD and we don't have a handler for it # retry with GET. if meth isNoneand request.method == "HEAD": meth = getattr(self, "get", None)
#: A list of methods this view can handle. methods = None
#: Setting this disables or force-enables the automatic options handling. provide_automatic_options = None
decorators = ()
@classmethod defas_view(cls, name, *class_args, **class_kwargs): """Converts the class into an actual view function that can be used with the routing system. Internally this generates a function on the fly which will instantiate the :class:`View` on each request and call the :meth:`dispatch_request` method on it. The arguments passed to :meth:`as_view` are forwarded to the constructor of the class. """
if cls.decorators: view.__name__ = name view.__module__ = cls.__module__ for decorator in cls.decorators: view = decorator(view)
# We attach the view class to the view function for two reasons: # first of all it allows us to easily figure out what class-based # view this thing came from, secondly it's also used for instantiating # the view class so you can actually replace it with something else # for testing purposes and debugging. view.view_class = cls view.__name__ = name view.__doc__ = cls.__doc__ view.__module__ = cls.__module__ view.methods = cls.methods view.provide_automatic_options = cls.provide_automatic_options return view defdispatch_request(self): """Subclasses have to override this method to implement the actual view function code. This method is called with all the arguments from the URL rule. """ raise NotImplementedError()
# If the request method is HEAD and we don't have a handler for it # retry with GET. if meth isNoneand request.method == "HEAD": meth = getattr(self, "get", None)