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
HttpResponseis imported from thedjango.httpmodule. greetingis the view function that takes anHttpRequestobject as its first parameter namedrequest.- The generated response in an HTML format is returned as an
HttpResponseobject by the view.
No comments:
Post a Comment
If you have any doubts, Please let us know.