简体   繁体   English

在本地运行的基本HTML页面中显示Python脚本的结果

[英]Show result of Python script in basic HTML page running locally

I want to build a very simple web page running LOCALLY on my computer, displaying results from a Python script. 我想构建一个非常简单的网页,在我的计算机上本地运行,以显示Python脚本的结果。 I have tried using HTML and PHP but without any luck. 我尝试使用HTML和PHP,但没有任何运气。 Please bear in mind that I'm a complete newbie in web development. 请记住,我是Web开发方面的新手。

Let's say I want to very simply print some text on the web page. 假设我想非常简单地在网页上打印一些文本。 This is what "helloworld.py" looks like: 这是“ helloworld.py”的样子:

print("hello world")

This is what helloworld.html looks like: 这是helloworld.html的样子:

<html>
<body>
<?php
$message = exec('helloworld.py');
print_r($message);?>
</body>
</html>

However, when I open the HTML file in the browser I just get an empty screen. 但是,当我在浏览器中打开HTML文件时,我只会得到一个空白屏幕。 Can someone tell me how to do this? 有人可以告诉我该怎么做吗?

you're going to need a webserver to serve the webpages on localhost using php. 您将需要一个网络服务器来使用php在localhost上提供网页。 since you mentioned that you're a beginner peek at php it covers the fundamentals. 因为您提到您是php的初学者,所以它涵盖了基础知识。 as for the webserver, since it's a local project, you're welcome to use xampp or if you're adventurous use apache. 至于网络服务器,由于它是本地项目,因此欢迎您使用xampp,或者如果您喜欢冒险,请使用apache。 save your .html as .php and embed the html code inside. 将.html保存为.php并将html代码嵌入其中。 there's a tutorial in the link. 链接中有一个教程。 also make sure to take a peek at the documentation for php enabled pages and another nice tutorial by udemy xampp 还请确保浏览一下启用php的页面的文档以及udemy xampp撰写的另一个不错的教程

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

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