CircuitPython_HTTPServer return data

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tomahawksmail
 
Posts: 4
Joined: Mon Oct 19, 2020 8:40 am

CircuitPython_HTTPServer return data

Post by tomahawksmail »

Hi all. I have a question.
How can I return the value of a variable to an HTML template using FileResponse?

It's python code snippet

Code: Select all

@server.route("/")
def home(request: Request):
    Version = '0.0.1' # this value i want to recieve in HTML (index.html page)

    return FileResponse(request, "index.html", "/static")
It's HTML code snippet

Code: Select all

<title>Smart Aquarium {Version}</title>

I used Flask before and everything was clear there. Like that.

Code: Select all

@app.route("/login", methods=['POST', 'GET'])
def login():
    some code
    return render_template('login.html', version=version)
Maybe I'm using the wrong method? In any case, I'd really like to be able to pass in the HTML page template (with css and js) and the data that my function generates.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”