Defining a View
Views are defined in the file views.py
within the app directory.
A sample definition would be
from django.http import HttpResponse
def greeting(request):
html = "<html><body>Welcome to Django</body></html>"
return HttpResponse(html)
- The class
HttpResponse
is imported from thedjango.http
module. greeting
is the view function that takes anHttpRequest
object as its first parameter namedrequest
.- The generated response in an HTML format is returned as an
HttpResponse
object by the view.
No comments:
Post a Comment
If you have any doubts, Please let us know.