How to include python script in HTML file?

How to put this python script:

a = ['f','d','s','a']
x = -1
scope = vars()
for i in a:
    scope['x']+=1
    print a[x]

inside html file?

+3
source share
7 answers

Something like this, if you want to create html, you don't have to display it:

 html_file = open('namehere.html','w')
 a = ['f','d','s','a']
 x = -1
 scope = vars()
 data = ''
 for i in a: #TIP: use a generator
     scope['x']+=1
     data += a[x]
     data += '\n'
 html_file.write(data)
 html_file.close()
+3
source

If your web server supports it, you can run it as a CGI script to output an HTML file - here is more detailed information: http://www.penzilla.net/tutorials/python/cgi/

You will need to modify your script in order to output the correct HTML code, but this tutorial should get you started.

Good luck

+3
source

. Python PHP;

<?php

.

, - Python ( ), CGI ( ), Python -.

(, HTML), Javascript PHP. Python -.

+1

script , JSON-RPC
JSON-RPC

+1

<body> <head>, .

, , , print fdsa, :

<head>
<body>
fdsa
</body>
</head>

python script. , , , .

0

, CGI - , :

http://docs.python.org/library/cgi.html

http://www.penzilla.net/tutorials/python/cgi/

For instance:

print "Content-Type: text/html"     # HTML is following
print                               # blank line, end of headers

print "<html><head></head><body><pre>"
a = ['f','d','s','a']
x = -1
scope = vars()
for i in a:
    scope['x']+=1
    print a[x]
print "</pre></body></html>"

Hope this helps. Good luck

0
source

You can not. If you want to run the script in an HTML file, try using a different language, such as JavaScript or PHP. To enable javascript, enter the following:

<script type="text/javascript">
    // ...
</script>

Or in HTML5 you don’t even have to enter an attribute type:

<script>
    // ...
</script>

To enable PHP, enter

<?php
    // ...
?>
-1
source

Source: https://habr.com/ru/post/1774439/


All Articles