Page.add_function#

Page.add_function(func)[source]#

Adds a function to the Page. This function can be called from an HTML element.

Warning

If you added a Python function, users might be able to call this function from the client-side. Choose wisely the functions you add.

Examples

Consider an HTML code that contains the following:

>>> html_with_function = '<html><button onclick="printValue()">Print</button></html>'

Notice that the <button> element contains the attribute onclick calling a Python function printValue. However, this function is not yet added to the HTML page. To add the function, define it in Python and add it to a Page:

>>> def printValue():
...     print("value")
>>> page = Page(html_str=html_with_function)
>>> page.add_function(printValue)

Now create a Website and add the Page to it:

>>> from toui import Website
>>> app = Website()
>>> app.add_pages(page)
Parameters:

function – Function to be added to the page.

Return type:

None