简体   繁体   English

我需要配置什么才能在浏览器上运行 Python?

[英]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.我已经使用 Python 有一段时间了,但这是我第一次必须安装它并在 VPS 服务器上使用它。

I have the following script hello.py :我有以下脚本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".如果我在位置project/cgi-bin/hello.py上运行该文件,浏览器会显示“内部服务器错误”。 In console the error is: No such file or directory: exec of /project/cgi-bin/hello.py .在控制台中,错误是: 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.如果我在位置project/hello.py上运行该文件,浏览器将显示纯文本。

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.我读了很多书,我认为问题可能与 de HTTP 或 Apache2 目录上的某些配置有关。

I would greatly appreciate your help.非常感谢您的帮助。

You don't do anything.你什么都不做。 Python does not and cannot run in a browser. Python 不能也不能在浏览器中运行。

You could try to open a browser with webbrowser.您可以尝试使用 webbrowser 打开浏览器。 Safe your HTML code in a separated HTML-file.将 HTML 代码保存在单独的 HTML 文件中。 Have a look at the Docs .看看文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 要在我的浏览器中成功运行一个执行Python脚本的网站,我需要什么? - What do I need to successfully run a website in my browser that executes Python scripts? 如何将“flask”配置为仅从浏览器运行文件? - How do I configure “flask” to just run files from the browser? 从命令行在Linux上运行Python GUI程序需要什么软件包 - What Packages do I need to run a Python GUI program on Linux from the command line Python:要在Unittest中运行Selenium,我需要在程序目录中包括哪些模块? - Python: What modules do I need to include in the directory of my program to run Selenium with Unittest? Python 方法不起作用我需要做什么? - Python method not working what i need to do? 如何配置Wing101以运行Python 3.3? - How do I configure Wing101 to run Python 3.3? 什么是python配方,我该如何运行? - What is a python recipe and how do i run it? 当使用Pydev插件选择“运行”或“调试”时,如何配置Eclipse以启动浏览器 - How do I configure Eclipse to launch a browser when Run or Debug is selected using Pydev plugin Python:-如果即使屏幕锁定,我也想使android应用程序在后台运行。 我需要Android的哪些权限? - Python:- If i want to make an android app to run in background even if the screen is locked. What permission do i need for that from android? 如何使用Python 3.7在浏览器中运行html代码? - How do I run an html code in browser using Python 3.7?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM