Views

A view is a simple function which takes a request and returns a response. The response is then sent to the user, it can be a simple HTML page, a request or anything.

import rivr

def example_view(request):
    return rivr.Response('<html><body>Hello world!</body></html>')

Class-based views

A class-based view is a class which is callable, so it acts just like a normal function based view. rivr provides a base view class which allows you to implement methods for the different HTTP methods it wants to handle. For exaple:

class BasicView(View):
    def get(self, request):
        return rivr.Response('Get request!')

    def post(self, request):
        return rivr.Response('Post request!')

rivr also provides a other views such as RedirectView.

class rivr.views.View(**kwargs)
classmethod as_view(**kwargs)

This method will return a callable which will generate a new instance of the class passing it the kwargs passed to it.

Usage:

view = View.as_view()
response = view(request)
class rivr.views.RedirectView(**kwargs)

The redirect view will redirect on any GET requests.

Members:url, permanent
get_redirect_url(self, **kwargs)

Return the URL we should redirect to