Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python输入数据并显示输入的数据_Python_Apache - Fatal编程技术网

使用python输入数据并显示输入的数据

使用python输入数据并显示输入的数据,python,apache,Python,Apache,我是python的新手,我正在尝试编写一个可以打印输入数据的程序 这是我试过的程序 #!"C:\python34\python.exe" import sys print("Content-Type: text/html;charset=utf-8") print() firststring = "bill" secondstring = "cows" thridstring = "abcdef" name = input('Enter your name : ') print ("Hi %

我是python的新手,我正在尝试编写一个可以打印输入数据的程序

这是我试过的程序

#!"C:\python34\python.exe"

import sys

print("Content-Type: text/html;charset=utf-8")
print()
firststring = "bill"
secondstring = "cows"
thridstring = "abcdef"
name = input('Enter your name : ')
print ("Hi %s, Let us be friends!" % name)
此程序的输出仅为:输入您的姓名: 我无法从键盘输入任何内容。我在本地主机中使用apache运行这个程序,就像
有人能帮我打印用户输入的数据吗。谢谢。

只有从命令行运行该程序,这才有效

您正在尝试将其作为web应用程序运行,这两种情况截然不同

HTTP是一种基于请求-响应的协议。 您向服务器发送一个请求,服务器运行一些代码。在本例中,您提出的代码,服务器向您发送响应

输入从stdin读取,因此在这种情况下无法工作

您需要做的是制作一个用户提交的HTML表单,使用python的cgi模块读取该表单,然后发送一个包含名称的答案

这真的很难详细解释,因为有太多的事情要说


阅读更多关于HTTP、CGI、服务器端代码和python的信息,你会很好。

谢谢你提供的信息。你能推荐一些可用于web应用程序的数据库库来存储数据吗?如果你想继续使用python,你应该使用像cherrypy或django这样的框架。对于数据库,请查看sqlalchemy ORM。