Introduction💁
Before we dive into SQLFORMS, we need to understand web2py. So what is web2py? Web2py is an open-source web application framework that is written in the Python programming language. It is used to create dynamic web pages using Python. It cuts down a lot of tedious hard work of creating a webpage, such as creating a form from scratch.

SQLFORM📝
So when the form is created, the developer might need to store the data present in the form in a database. That is when the SQLFORM comes into role. The SQLFORM is used to create a new database record whenever the form is accepted. The values provided in the form can be stored in a database using the SQLFORM in the web2py framework. SQLFORM has many signatures, and we will briefly discuss each in brief in this blog.
Let us look at all the signatures present in the SQLFORM,
SQLFORM.grid(
query,
fields=None,
field_id=None,
left=None,
headers={},
orderby=None,
groupby=None,
searchable=True,
sortable=True,
paginate=20,
deletable=True,
editable=True,
details=True,
selectable=None,
create=True,
csv=True,
links=None,
links_in_grid=True,
upload='<default>',
args=[],
user_signature=True,
maxtextlengths={},
maxtextlength=20,
onvalidation=None,
onfailure=None,
oncreate=None,
onupdate=None,
ondelete=None,
sorter_icons=(XML('▲'), XML('▼')),
ui = 'web2py',
showbuttontext=True,
_class="web2py_grid",
formname='web2py_grid',
search_widget='default',
advanced_search=True,
ignore_rw = False,
formstyle = None,
exportclasses = None,
formargs={},
createargs={},
editargs={},
viewargs={},
selectable_submit_button='Submit',
buttons_placement = 'right',
links_placement = 'right',
noconfirm=False,
cache_count=None,
client_side_delete=False,
ignore_common_filters=None,
auto_pagination=True,
use_cursor=False,
represent_none=None,
showblobs=False
)
Now that we know the name of all the fields present in the SQLFORM.grid let us talk about them in detail. We will discuss as many fields as we can in this blog.
| Field Name | Field Description |
| fields | The fields signature is used to specify all the fields that need to be fetched from the database. Users can also enable the reading and writing of fields using the readable and writable signature. |
| field_id | This signature is used to determine the primary field for the grid. This comes in handy when the developers are dealing with multiple grids. |
| headers | The headers signature is used to map the field name into the corresponding header label. |
| groupby | This signature is used to define the default grouping mechanism for the selected fields. |
| orderby | This signature is used to define the default ordering mechanism for the selected fields. |
| searchable | This is a boolean-type field and defines whether the records in the grid are searchable or not. |
| deletable | This is a boolean-type field and defines whether the records in the grid are deletable or not. |
| sortable | This is a boolean-type field and defines whether the records in the grid are sortable or not. |
| details | This is a boolean-type field and defines whether the details of the records in the grid can be viewed or not. |
| editable | This is a boolean-type field and defines whether the records in the grid are editable or not. |
| create | This is a boolean type field and defines whether new records can be created in the grid or not. |
| selectable | The selectable signature is used to call a user-defined function on several records. |
| selectable_submit_button | Developers can add a basic button in the checkbox column of the grid using this signature. |
| paginate | The paginate signature is used to set the maximum number of records per page. |
| links | The link signature is used to add hyperlinks for another website as records in the grid. |
| csv | The csv signature can be used to enable users to download the grid in various formats. |
| links_in_grid | This signature is used to display the values in the main grid. The default value of this signature is true. |
| maxtextlength | This signature is used to set a maximum length for all the fields in the grid. |
| upload | The upload signature is used to allow the users to upload various files. |
| onvalidation, onupdate, onfailure, oncreate, and ondelete | These signatures are used to enable the callback functions in the controller files. They are called in case of validation, update, failure, create and delete, respectively. |
| sorter_icons | This signature is used to display two strings as a representation for the up and down sorting option in the grid. |
| search_widget | This function is used to override the primary search widget. |
| showbuttontext | This signature is used to enable or disable the texts on the button. |
| advanced_search | This signature is used to enable or disable the advanced search option for the grid. |
| _class | Developers can add the name for the grid using this signature. |
| button_placement and link_placement | These signatures are used to define the placement of the button and the link in the row. |
| noconfirm | This is used to add an additional warning when the user tries to delete a record. |
| cache_count | This signature is used to speed up the counting process of the rows. |
| auto_pagination | This is used to enable pagination for all the records. |
| use_cursor | This signature is used to enable the cursor for pagination. |
| represent_none | This signature is used to display a custom message instead of the none value in the grid. |
| showblobs | This signature is used to display the gird fields to show the fields with blob type. By default, blob types are not displayed. |
Virtual Fields💻
Virtual Fields are fields whose values are calculated automatically by the compiler using the other fields of the table.
In the versions above 2.6 of the web2py, the virtual fields are automatically displayed in the grid alongside the normal fields. However, we cannot sort the virtual fields.
In the older versions of web2py, developers had to explicitly display the virtual fields using the link field. Developers had to use the following code snippet to import a virtual field,
grid = SQLFORM.grid(database.table1, ..., fields = [table1.field1, table1.field2, ...],
links = [dict(header='Virtual Field', body=lambda row:row.vfield), ...] )
Frequently Asked Questions
What is SQLFORM.grid?
The SQLFORM.grid is used to provide the users with the ability to search, create, browse, sort, update, and delete records from one object. The SQLFORM.grid is based on SQLFORM and is quite similar to it.
What is web2py?
Web2py is an open-source web application framework that is written in the Python programming language. It is used to create dynamic web pages using Python. It cuts down a lot of tedious hard work of creating a webpage, such as creating a form from scratch.
What are Signatures?
Signatures are additional fields passed to a method for more precise computation. Some signatures may be compulsory to include, and some may be optional. For example, fields is a mandatory signature, whereas pagination is an optional signature.
How to download the web2py framework?
We can install web2py from the official website of web2py.
We can also use the following commands on our command prompt to install web2py
- UNIX and Linux: web2py.py
- OS X open: web2py.app
- Windows: web2py.exe
What is the default port in web2py?
The default port in web2py is set to 8000, but developers can change it at any time. Developers can also change the admin password according to their own convenience.




