xralf
xralf

Reputation: 3642

Python scripts in HTML

Is it possible to write Python scripts in HTML code similarly as you write PHP between <?php ... ?> tags?

I'd like to achieve that my Python application will run in the browser.

thank you for help

Upvotes: 9

Views: 50545

Answers (5)

rassa45
rassa45

Reputation: 3550

Well, this might be overkill, but you can install a localhost xampp server. Then, just put the right comments at the top of the file to direct xampp to the interpreter, and you can print out html or regular words right from the language itself. For example, a Python script like this

#!/Python34/python

print "Content-type: text/html"
print

print "Hello World"

Would give a webpage saying Hello World

Upvotes: -1

Mr. Lance E Sloan
Mr. Lance E Sloan

Reputation: 3387

A newer answer for an older question: There is a Python framework called Karrigell that supports what it calls "Python Inside HTML". It interprets Python from HTML files with a ".pih" extension.

I've not tried Karrigell, but it looks compelling.

Upvotes: 1

highBandWidth
highBandWidth

Reputation: 17321

PHP doesn't run in the browser, as it is a server side language. You could try Skulpt to try to run python in the browser.

Upvotes: 7

Gustav Larsson
Gustav Larsson

Reputation: 8487

Python indentation requirements don't go well with mixing HTML and Python code. Therefore, the most prominent method (which is a framework called Django), uses a template engine so that the Python is never in direct contact with the HTML code.

It will be similar to PHP and not javascript, as it will run on the server-side.

There is also mod_python for Apache, but I would strongly recommend using Django, which also runs on an Apache server.

Upvotes: 8

user2665694
user2665694

Reputation:

You are mixing up client-side and server-side execution of code.

Browsers support only Javascript.

Any application-server or Python-based webframework support template language where you can mix HTML and Python in some way or the other.

Upvotes: 2

Related Questions