Python
This guide will show how to use hop
in a Python
backend.
We start by writing a simple hop
file.
hop
<page-index {name: String}>
Hello {name}!
</page-index>
Now we compile the hop
code to native Python
code.
bash
hop compile
Now the generated Python
code is available in the folder ./frontend
so we can import it in the backend.
Now, let's define a simple backend using Flask.
python
from flask import Flask
import frontend
app = Flask(__name__)
@app.route('/')
def index():
return frontend.page_index(
frontend.PageIndexParams(
name="Tobi"
)
)
if __name__ == '__main__':
app.run(port=8080)
Now hop
is integrated into the backend, and we can run hop dev
to start the server and get hot-reloading.