Call a python function within a html file

You’ll need to use a web framework to route the requests to Python, as you can’t do that with just HTML. Flask is one simple framework:

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

def index():
  return render_template('template.html')

def my_link():
  print 'I got clicked!'

  return 'Click.'

if __name__ == '__main__':


<!doctype html>

<meta charset=utf-8> 

<a href="">Click me</a>

Run it with python and then navigate to http://localhost:5000/. The development server isn’t secure, so for deploying your application, look at

Leave a Comment