'How to execute python code on client side using flask?

I have my server.py file, where i have:

from flask import Flask,render_template,url_for
app=Flask(__name__)

@app.route("/")
@app.route("/home")
def home():
  return render_template("home.html",posts=posts,title="arroz") 

if __name__=="__main__":
  app.run(debug=False)

My home.html file has:

{%extends "layout.html"%}
{%block content%}
  <!--here-->
{%endblock content%}

I want to execute some python code in a python file on the client side in the comment here on the home.html file. I can't just call regular python code from flask, because that would run on the server side. How can I run it on the client side?

My project's structure is the following:

|-server.py
|-pythonToExecuteOnClientSide.py
|-templates
      |-home.html


Solution 1:[1]

This won't work since Python is not a web-app language supported by browsers. Everything that is client-side needs to be able to run on the client computer and for Python code you need to have Python installed on your computer.

The only option you have is to code your feature in JavaScript to let it run on the client side.

Why exactly do you want it to run on the client side? Maybe there is a different solution for your problem. Like a server-client program.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jonii