Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Response in web2py 
Frequently Asked Questions
What is the web2py framework?
What is the default port of Web2py?
What are the features of Web2py?
Is web2py an MVC model?
Does web2py support Python 3?
Which is better, web2py or Flask?
Last Updated: Mar 27, 2024

Response in web2Py

Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @


Web2Py is written in Python and programmable in Python. A free, open-source web framework named Web2py allows for quickly creating safe, database-driven online applications. Web2py is a full-stack framework that includes all the components needed to build fully functional online applications.

Introduction image

Web2py is the ideal framework for a Python programmer who wants to build a website utilizing a quick, open-source, full-stack framework. Web2py assists us in creating database-driven web applications that are quick, scalable, and portable. 

We will now learn about Postbacks and Internationalization in Web2py in this article.

Let us get started now 

Response in web2py 

Response in Web2py

The response is another instance of the storage class. It mainly contains 

  • response.body: web2py writes the output page body into a StringIO object. DO NOT CHANGE THIS ELEMENT.
  • response.cookies: similar to request. cookies, however, the former contains cookies that the server sends to the client, and the latter contains cookies that the client sends to the server. The handling of the session cookie is automatic.
  •, db): a procedure for carrying out the controller function that enables downloaded files from uploaded files.
  • expects the final argument in the request. the encoded filename in args (i.e., the filename generated at upload time and stored in the upload field). From the encoded filename, it retrieves the names of the upload field and table as well as the original filename.
  • takes two optional arguments: The parameters attachments and chunk size control whether or not the downloaded file should be considered as an attachment. The default value for chunk size is 64K. (default to True). Please note that is only for use with files linked to database upload fields. Use response if you need to download or stream other (see below). Also take notice that accessing files uploaded to the /static subdirectory does not require the usage of; instead, static files can (and usually should) be accessed directly through URL (e.g., /app/static/files/myfile.pdf).
  • response.files: a list of the.css, js, coffee, and fewer files that the page requires. The supplied "web2py ajax.html" will automatically link to them in the head of the standard "layout.html." Add a new CSS, JS, COFFEE, or LESS file to this list to incorporate it. It'll deal with duplicates.
  • response.include_files(): creates HTML head tags for "views/web2py ajax.html" that include all response.files.
  • response.flash: the optional component that the views could use. Typically used to inform the user of a recent event.
  • Views may have an optional parameter to pass a navigation menu tree to the view. The MENU helper can render it.
  • response.meta: a storage item that includes optional "meta" data like "author," "description," and "keywords." The code in "views/web2py ajax.html," which is automatically included in "views/layout.html," places the contents of each meta variable in the appropriate META tag.
  • response.include_meta(): creates a string containing every response. serialized meta headers are utilized in "views/web2py ajax.html."
  • response.postprocessing: Normally empty, this is a list of functions. Before the view renders an action's output, these functions filter the response object at the output. The implementation of support for other template languages is possible using it.
  • response.render(view, vars): a technique used to call the view inside the controller explicitly. vars is a dictionary of named values supplied to the view, and the view is an optional parameter that contains the name of the view file.
  • response.session_file: the session's file stream.
  • response.session_file_name: filename where the session will be saved.
  • response.session_id: The session identifier for the current request. Automatic determination is made.
  • response.session_id_name: This application's session cookie's name.
  • response.static_version: a version number for the response.files static asset management.
  • response.static_version_urls: Any link to the static folder can use static asset management if this is set to True.
  • response.status: the response will receive the integer representing the HTTP status code. By default, 200 (OK).
  • response.status: the response will receive the integer representing the HTTP status code. By default, 200 (OK).
  • response.subtitle: optional component that the views could use. It needs to have the page's subtitle.
  • response.title: the optional component that the views could use. It should be rendered inside the html title tag in the header and contain the page's title.
  • response.toolbar() is a function that enables you to embed a toolbar into a website for debugging purposes. The toolbar shows the request, response, session variables, and database access time for each query.
  • response._vars: Only a view can access this variable; the action does not. It includes the values that the action sent to the view.
  • response._caller: This function covers all calls to action. It is set to use the identity function by default, but it can be changed to catch certain exceptions and perform further reporting

    response._caller = lambda f: f()
  • response.optimize_css: Concatenate, minify, and inline the CSS files that web2py includes by setting the option to "concat, minify, inline.
  •  response.optimize_js: The JavaScript files supplied by web2py can be concatenated, minified, and inlined by setting the parameter to "concat,minify,inline."
  • response.view: the name of the page-rendering view template. The default setting for this is:
"%s/%s.%s" % (request.controller, request.function, request.extension)

alternatively, if the aforementioned file cannot be found,

"generic.%s" % (request.extension)


To alter the view file linked to a specific action, alter the value of this variable.

  • response.delimiters: standard value is (‘{{’,’}}’). Using this tool, you can alter the delimiter of code embedded in views.
  • response.xmlprc(request, method): This function exposes the methods via XML-RPC when a controller returns it.
  • Consider the following code, for example, in the "" controller:

def add(a, b):
    return a + b

def div(a, b):
    return a / b


Now in the python shell, you can do: 

>>> from xmlrpclib import ServerProxy
>>> server = ServerProxy(
>>> print server.add(3, 4)
>>> print server.add('hello', 'world')
>>> print server.div(12, 4)
>>> print server.div(1, 0)
ZeroDivisionError: integer division or modulo by zero
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Frequently Asked Questions

What is the web2py framework?

An open-source web application framework called Web2py. It enables the creation and design of dynamic web applications.

What is the default port of Web2py?

Web2py default port is 8000.

What are the features of Web2py?

Web2py features are: easy to learn, a portable, standard library that supports many tasks.

Is web2py an MVC model?

The Ruby on Rails and Django frameworks inspired the creation of web2py. Web2py is similar to these frameworks in that it emphasizes rapid development, prefers convention over configuration, and adheres to the model-view-controller (MVC) architectural pattern.

Does web2py support Python 3?

Web2py functions on Python 2.7 and Python 3 along with CPython (the C implementation) and PyPy (Python written in Python).

Which is better, web2py or Flask?

The majority of the Slant community suggests Flask when comparing web2py to that framework. What are the best backend web frameworks, as in the question? Web2py is ranked 19th, while Flask is placed fourth. 


This article has an extensive understanding of response in web2py and the attributes of response in web2py.  

After reading about  Other types of Forms in web2py, refer to the web2py web framework,

What is the web2py web frameworkweb2py introductionweb2py installationCreating a New Web2Py ApplicationWeb2Py - Prepare the ToolWeb2Py - Troubleshooting Use Cases, and Web2Py - Capacity Planning Use CasesApplication development using PythonIntroduction to Python- Coding Ninjas for a deeper understanding of web2py development and other related topics. 

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! 

Live masterclass