Ask coding questions

← Back to all posts
How to add python to HTML
Mendelevium (43)

Hi, I've looked up different ways to add python to HTML, but none seem to work. Does anyone know how to add python into an HTML page?

Answered by AdCharity (1328) [earned 5 cycles]
View Answer
AdCharity (1328)

@Vandesm14 While it isn't exactly possible to add python to HTML, it is very possible to mix programming languages, such as making web servers with python. For instance, here:
Be sure to close out this post (meaning mark the official answer) if you got your answer :) Btw. this is kind of a duplicate of
The easiest way to put this is basically:

In addition, you could technically make an iframe of a repl with python.... but that's kind of fishy

Mendelevium (43)

Thank you so much for the link, @AdCharity

RiaDebnath1 (0)

@AdCharity Hello, when I use this I get 'Internal Server Error' and

"The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."

any idea how to fix? :)

AdCharity (1328)

well to start // are commas for javascript so you'd have to change those. Also, there is a specific way to set up the "render template" function. The file structure will have to look like this:

RiaDebnath1 (0)

@AdCharity I'm so sorry but I'm doing this and still getting an error? Can I please add you to collaborate on the program?

AdCharity (1328)

@RiaDebnath1 Hey please check out the official flask documentation, there's some quick start examples.

Ruchikasliwal (0)

no, even i wanna know. forget grammar

AustinBPark (18)

what I would do is embed a output or use an iframe. But i dont think that works with graphics libs.

Vandesm14 (2759)

There is no way to add python to HTML. Only JavaScript works with HTML.

AphixDev (204)

@Vandesm14 That's not true at all. Python is a server side language originally created for HTML. Here's some reference:

Vandesm14 (2759)

@nt998302 But it's not "to HTML". JavaScript is the only language that works with HTML. While python can be used as a server-side language, that's not truly pairing python with HTML, which is what he was asking.

Zavexeon (1166)

Hmm... you'd need to use a template engine. Look at this stackoverflow thread.