9

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

1

5 Answers 5

8

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Django is similar as CMS? Can it exist simultaneously with my Drupal installation?
@xralf Django does make it easy to create CMS systems, but it's not a CMS system per se. And yes, you can still keep PHP/Drupal on the server and use it separately from Django.
Indentation is the one thing about Python that I like the least. If the indentation is the main reason why Python hasn't been embedded in HTML, then that gives me even more reason to dislike it.
7

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.

Comments

2

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.

1 Comment

>> You are mixing up client-side and server-side execution of code. ... It was my intension to name one server-side and one client-side scripting language, because I didn't know exactly what I want, but it seems that client side is for my purpose more convenient.
1

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.

Comments

-1

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

1 Comment

xampp works with php, perl, and almost any scripting language out there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.