Search This Blog

View Response Types - Python

 

View Response Types
Other than HTTPResponse we can use other inbuilt functions that can be used to respond to requests.

These are referred as Django shortcut functions. They are

  • render() - Returns HttpResponse object by rendering the output on a template. Request and template_name are required arguments.
  • redirect() - The view response is directly sent to a URL. This is the URL reversing concept and can be used either with a model or a view name or a direct URL as an argument.
  • get_object_or_404 - Used when you need to get specific data from a model and return the model object. This raises Http404 exception when the object is not found.
  • get_list_or_404 - Used when you need to get a list of model objects and returns Http404 exception if the list is empty.

No comments:

Post a Comment

If you have any doubts, Please let us know.