django-viewsGetting started with django-views


Remarks

This section provides an overview of what django-views is, and why a developer might want to use it.

It should also mention any large subjects within django-views, and link out to the related topics. Since the Documentation for django-views is new, you may need to create initial versions of those related topics.

Django Views

Django Views are simply the functions that get called when a request is made to a certain URLs.
URL patterns are written in urls.py file, each URL regex is given a function(Django view) from a views.py , so when a request is made, that function gets the call, with the HTTP request object, and then you can do whatever fun you want to do with that request.

A simple example of view,

from django.http import HttpResponse
import datetime

def current_datetime(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)
 

Calling the above view from a URL would return the current time, everytime you call the URL assigned to this view.
The request object has many parameters related to the HTTP request you get, like headers, request type and more. Read the official doc with more detailed examples.

Installation or Setup

Detailed instructions on getting django-views set up or installed.