Run a python application inside a php div?

Does anyone know if I can run a python application inside a php div?

An example would be to have a php with a menu… and in a central div, invoke my that to do a test would be the following:

from flask import Flask, render_template

app = Flask(__name__)

def hola():
    return render_template("hola.html")

if __name__=='__main__':

There is no such thing as “a php div”, so it’s hard to understand the question.

PHP is a programming language, generally used on the server to create HTML. It serves the same sort of purpose as your existing Flask templates, so it can’t really help you with this project.

Only JavaScript runs natively on the client. If you want the user’s computer to do a calculation, write JavaScript code as part of the template. When the user loads the web page, that JavaScript can then run.

If you want the web page to “invoke” something on the server, like you say, then you should write JavaScript code that makes an AJAX request. There are many libraries that simplify this process, but the general idea is that the JavaScript code can directly request an “API” route that you define in your app, instead of the user having to load a URL (from clicking a link or typing in an address). The Javascript code will then receive whatever data is sent back from that route. Instead of rendering a template in these cases, you should have separate routes for the API that will return JSON data instead. This is much easier to process from the JavaScript code. You can then write the JavaScript code so that it takes this data and does whatever it has to on the user’s computer, such as adding new HTML elements to the page.

If you want to use a different language on the client (such as Python), you will need to use a JavaScript library that translates the code to JavaScript first. For Python, you can do this with Brython.

I was asking because currently I have an intranet on the one hand programmed in php where I have the menu part, footer… and in the central part appears what you are sending from the lateral menu.
Currently there are applications but in the same php language and I wanted to couple my application in python, doing the same, from the menu click and show my application.

From what I’ve been looking at it seems that it can be done but for the moment I’ve only seen very basic examples that only show a text programmed in python and my application does more things and needs modules apart from flask, that part is the one I don’t know How would it be so that you can interpret the entire application.