#!/usr/bin/python doesn't run in chrome webbrowser, only shows file code

  1. I made a file Test.html:
Interactive Page

Enter your name:

  1. When input is finished, Chrome doesn’ run the Test.py file, only shows the code in the browser:

#!/usr/bin/python
import cgi
form = cgi.FieldStorage() # parse form data
print(‘Content-type: text/html\n’) # hdr plus blank line
print(‘Reply Page’) # html reply page
if not ‘user’ in form:
print(‘

Who are you?

’)
else:
print(‘

Hello %s!

’ % cgi.escape(form[‘user’].value))

Can somebody plse explain me what’s the issue here?

thx!

Please put your code inside code-fences/preformatted text like this:

```
def main():
     print('Hello')
```

Web browsers do not run scripts as you seem to be attempting to do.
That is the job of a web server. Have you added your script to a web server? What web server and running on what OS?

Also its more usual for the CGI script to be named test.cgi not test.html.
For example with apache httpd I would put the test.cgi in its cgi-bin folder.

Hi,

Thanks for your reply :blush:, and sry, I’m just starting and rather new with Python…

My OS is Windows 11 Home
I installed Apache24 (C:\Apache24):

The first file I used was ‘Test.html’:

`

Interactive Page

Enter your name:

` ` ` Opening with Chrome: *(see uploaded screenshot)* ![screenshot Mail PythonForum|690x455](upload://16FwITJ2YQ4EiaK93hODWhRoG7P.png)

Problem is that once a name has been submitted, the file ‘Test.py’ isn’t opening in Chrome, just the file code is appearing:

I suppose I’m missing something…

Rgds,

Marc

You must configure httpd to know what folders and file type can be executed.

Usually there is a folder named cgi-bin that you can put scripts into.
Then you can browse to http://localhost/cgi-bin/test.py I expect.

I use httpd in linux and may have missed a Windows specific detail.

If tou are still stuck search the web for how to run cgi scripts with httpd on windows.