简体   繁体   English

是否可以使用Really Simple HTTP Server在Python中编写动态网页?

[英]Is it possible to write dynamic web pages in Python with the Really Simple HTTP Server?

I know that with the SimpleHTTPServer I can make my directories accessible by web-browsers via Internet. 我知道使用SimpleHTTPServer,我可以通过Internet访问Web浏览器。 So, I run just one line of the code and, as a result, another person working on another computer can use his/her browser to see content of my directories. 因此,我只运行一行代码,因此,另一个在另一台计算机上工作的人可以使用他/她的浏览器查看我的目录内容。

But I wander if I can make more complicated things. 但是如果我能做出更复杂的事情,我就会徘徊。 For example, somebody uses his/her browser to load my Python program with a set of parameter (example.py?x=2&y=2) and, as a result, he/she sees the HTML page generated by the Python program (not the Python program). 例如,有人使用他/她的浏览器使用一组参数(example.py?x=2&y=2)加载我的Python程序,结果,他/她看到了Python程序生成的HTML页面(不是Python程序)。

I also wander if I can process html form submitted to the SimpleHTTPServer. 如果我可以处理提交给SimpleHTTPServer的html表单,我也会徘徊。

While it is possible, you have to do pretty much everything yourself (parsing request parameters, handle routing, etc). 尽管有可能,但您必须自己完成所有事情(解析请求参数,处理路由等)。

If you are not looking to get experience in creating web-frameworks, but just want to create a small site you should probably use a minimalistic framework instead. 如果您不希望获得创建Web框架的经验,但只想创建一个小型站点,则应该使用简约框架。

Try Bottle, a simple single-file web framework: http://bottlepy.org Try Bottle,一个简单的单文件Web框架: http//bottlepy.org

Maybe the VerseMatch project and related recipes over at ActiveState is something you would be interested in examining? 也许VerseMatch项目和ActiveState上的相关配方是你有兴趣检查的东西吗? It implements a small application using the standard library for dynamic running. 它使用标准库实现了一个小型应用程序,用于动态运行。

have you considered using CGIHTTPServer instead of SimpleHTTPServer? 您是否考虑过使用CGIHTTPServer而不是SimpleHTTPServer? Then you can toss your scripts in cgi-bin and they'll execute. 然后你可以在cgi-bin中抛出你的脚本然后执行它们。 You have to include content-type header and whatnot but if you're looking for quick and dirty it's real convenient 你必须包含内容类型的标题和诸如此类的内容,但如果你正在寻找快速和脏的话,这真的很方便

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

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