简体   繁体   中英

What do I need to configure to run Python on a browser?

I have worked with Python for a while, but this is my first time that I have to install it and use it on a VPS server.

I have the following script hello.py :

#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

print '''
<!DOCTYPE html>
<html>
<head>
   <title>Hello</title>
</head>'''
print "Hello World!"

I haven't been able to run the file on a browser. I don't know if it has something to do with the location of the script or with some other permissions I need to consider. I think there is nothing wrong with the code, because I copy exactly the same in another server (which I didn't configure) it works fine. Also, If I run the script from the console, it also works.

If I run the file on the location project/cgi-bin/hello.py the browsers display "Internal Server Error". In console the error is: No such file or directory: exec of /project/cgi-bin/hello.py .

If I run the file on the location project/hello.py the browser displays plain text.

I've been reading a lot, and I think that maybe the problem has to do with some configuration on de HTTP, or Apache2 directory.

I would greatly appreciate your help.

You don't do anything. Python does not and cannot run in a browser.

You could try to open a browser with webbrowser. Safe your HTML code in a separated HTML-file. Have a look at the Docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM