Google News
logo
Django - Interview Questions
What is django.shortcuts.render function?
When a View function returns a webpage as HttpResponse rather than a simple string, we use render().
 
Render function is a shortcut function which lets the developer to easily pass the data dictionary with the template.
 
This function then combines the template with data dictionary via templating engine.
 
Finally, this render() returns an HttpResponse with the rendered text, which is the data returned by the models.
 
Thus, Django render() bypasses lots of work for the developer and lets him use different templating engines.
 
It is because this function provides the same functionality with other templating systems.
 
The basic render Syntax :
render(request, template_name, context=None, content_type=None, status=None, using=None)
 
The request is the parameter which generates the response, the template_name containing the value where the template is stored.
 
The template name and other parameters are for passing the dictionary.
 
If you want more control, you can specify the content type, status of the data you passed and the render you are returning. That is the render().
Advertisement