TemplatesΒΆ
This feature in the Radian framework enables the use of Brython Templates functionalities through HTML files.
For instance, the following is an example of the main.html
code:
<div class="">
<h1>Brython Templates</h1>
<h2>{title}</h2>
</div>
<div class="">
<h1>Brython Templates b-code</h1>
<h2 b-code="for item in items:">{item}</h2>
</div>
The usage is as follows:
[ ]:
from radiant.framework.server import RadiantAPI, RadiantServer, render
from radiant.framework import html
class StaticApp(RadiantAPI):
def __init__(self, *args, **kwargs):
""""""
super().__init__(*args, **kwargs)
self.body <= html.H1('Radiant-Framework')
self.body <= self.main()
def main(self):
""""""
context = {
'title': 'Title',
'items': [f'item-{i}' for i in range(10)],
}
return render('main.html', context)
if __name__ == '__main__':
StaticApp()
This code demonstrates the use of the render
function within the Radiant framework. It outlines the creation of a StaticApp
class, which inherits from RadiantAPI
. The class defines a constructor and a main method. The main method constructs a context containing a title and a list of items, and then it returns the output of the render
function. This function is used to integrate dynamic data from the context with an HTML template (main.html
), a common technique in web
applications for generating dynamic web pages.