Python scripts in HTML
Is it possible 开发者_JS百科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
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.
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.
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.
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.
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
精彩评论