Html Response

updated: 1 month, 3 weeks ago
html html response

HTML response

Each code component can send back an html response to the user by rendering an html template. A default template is available for each app and can be edited directly from the main  toolbar as shown below.

Edit default html template for your app directly from the toolbar

By clicking html icon in toolbar the html editor will be open with a blank default html template ready to use.


HTML editor with default blank html content

We need to render the template render_template('templates/template.html') and send back the user. To do this we will import render_template function from flask package. The only thing left to do is to send back the rendered template back to the user using self.result

from blockdx.blocks import SimpleBlock
from flask import render_template

class first_template(SimpleBlock):

    def __init__(self,inpt):
        super().__init__(inpt)
        
    def run(self,request):
        # Write your code here
        self.result = render_template('template.html')
    

        

The default html template is blank so let's edit it first to make it more interesting. By clicking on html icon in toolbar the template.html file will be open to be edited.

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
</head>
<body>
    <h1>Powered by Doprax</h1>
    <p>This is paragraph</p>
    <button>simple button</button>
</body>
</html>

After saving the template and saving app changes you need to click on run to run the app. By visiting the app URL the html response can be viewed as in picture below.