创建一个简单的 Python Web 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38861124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:32:19  来源:igfitidea点击:

Creating a simple python web application

pythonpython-2.7webwebapp2

提问by AlpU

I have a python script that takes inputs from commandline. I simply want to modify this script so I can run it on web. I want the commandline interface to be replaced by a simple boxes in a web page, and once the script is executed, I want the results to be shown on a webpage like it does in commandline.

我有一个从命令行获取输入的 python 脚本。我只是想修改这个脚本,这样我就可以在网络上运行它。我希望命令行界面被网页中的一个简单框替换,并且一旦执行脚本,我希望结果像在命令行中一样显示在网页上。

Any help on where to start, which python packages to use and which steps to take would be much appreciated.

任何关于从哪里开始、使用哪些 python 包以及采取哪些步骤的帮助将不胜感激。

Until now, I read a little about webapp2 for Google App Engine and web.py. I do not want to use Django.

到现在为止,我读了一些关于用于 Google App Engine 和 web.py 的 webapp2。我不想使用 Django。

Thank you!

谢谢!

采纳答案by FaureHu

While you can use a microframework like Flask [1] for quickly getting started, you can get closer to the metal. Try learning about the HTTP protocol and implement your own server using the httpmodule. Python 3's http.servercontains a class SimpleHTTPServer[2] which can be very good for understanding how you're communicating between the client and your process.

虽然你可以使用像 Flask [1] 这样的微框架来快速入门,但你可以更接近金属。尝试了解 HTTP 协议并使用该http模块实现您自己的服务器。Python 3http.server包含一个类SimpleHTTPServer[2],它非常有助于理解客户端和进程之间的通信方式。

[1] http://flask.pocoo.org/docs/0.12/quickstart/

[1] http://flask.pocoo.org/docs/0.12/quickstart/

[2] https://docs.python.org/2/library/simplehttpserver.html

[2] https://docs.python.org/2/library/simplehttpserver.html

回答by Devasta

Have you considered using Flask?

你考虑过使用 Flask 吗?

http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

This is a pretty great tutorial on how to make a basic webapp.

这是一个关于如何制作基本 web 应用程序的非常棒的教程。