如何使用Python作为像PHP这样的服务器端脚本语言? [英] How to use Python as a Server-side scripting language like PHP?

查看:341
本文介绍了如何使用Python作为像PHP这样的服务器端脚本语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Python语言,它的语法和其他功能与其他语言一样简单'',但我想将其用作服务器端脚本语言,例如带有Apache Web Server(AppServ)的PHP非常困难,我想我必须在配置文件中更改一些信息,但是更改内容对我来说并不容易.我的需求非常简单,例如,我有以下HelloWorld python文件:
#!E:/Python32/python.exe
print("Hello World!")


然后将其保存为" HelloPython.py ",并将其保存在" E:/AppServ/www/cgi-bin/"
并且我希望当用户在浏览器的地址栏中键入" http://localhost/cgi-bin/HelloPython.py "时,按Enter键,它应该显示"Hello World!". br/>
我在Google上进行了一些搜索,并尝试了以下操作:
选项+ ExecCGI
AddHandler cgi-script .py .pl

当服务器返回诸如"内部服务器错误"之类的消息时,配置文件的更改似乎已生效,并且我打开了服务器错误日志文件以查看发生了什么,并说"脚本中的标头格式错误.错误的标头= Hello World!:HelloPython.py ".好吧,标头格式错误???我从NotePad的保存文件"对话框中使用ANSI选项保存了python文件,这是怎么回事?

您能帮我解决这种麻烦吗?我觉得这根本不容易.
无论如何,我们将非常感谢您的帮助!谢谢!

Hi, I am researching on Python language, its syntax and other features are as easy as others'' but I want to use it as a server-side scripting language like PHP with Apache Web Server (AppServ) but it seems to very difficult, I think I have to change some info in configuration file but what to change are not easy to find out for me. My want is very simple, for example, I have the following HelloWorld python file:
#!E:/Python32/python.exe
print("Hello World!")


and I save it as "HelloPython.py" and save it in "E:/AppServ/www/cgi-bin/"
and I want when users type "http://localhost/cgi-bin/HelloPython.py" in the Address bar of a browser, hit enter and it should display the "Hello World!".

I have searched a little with Google and tried some things like:
Options +ExecCGI
AddHandler cgi-script .py .pl

And it seemed that the changes to the configuration file took effect when the server threw back a message like "Internal Server Error" and I opened the Server error log file to see exactly what happened and it said "malformed header from script. Bad header=Hello World!: HelloPython.py". Well, malformed header??? I saved my python file using ANSI option from the save file dialog of NotePad, what''s wrong with that?

Could your please help me out this complexity? I can feel it''s not easy at all.
Your help would be highly appreciated anyway, thanks!

推荐答案

您必须阅读以下文章:
http://wiki.python.org/moin/WebFrameworks [ http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442 [
You must read these articles:
http://wiki.python.org/moin/WebFrameworks[^]

http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442[^]

Hope it helps :)


查看Python的 CGI库的文档 [^ ]

基本上,您缺少HTTP标头,并且在文档中有一个带有简单标头的示例.
Check out the documentation for Python''s CGI library[^]

Basically, you''re missing an HTTP header, and there''s a sample in the documentation with a simple header.


Check out mod_python

http://www.modpython.org/


这篇关于如何使用Python作为像PHP这样的服务器端脚本语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆