为python应用程序创建一个Web服务 [英] create a web service for python application

查看:49
本文介绍了为python应用程序创建一个Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python web应用程序的新手。可以帮一些人。

我有一个python应用程序,里面有一些函数。


1)应用程序读取输入文件(例如,IN.txt)。

IN.txt文件包含同一目录中

的其他三个文件(x.dat,y.txt,z.dat)的名称。


2)然后应用程序读取文件x.dat,y.txt,z.dat中的数据并执行一些计算。


3)将结果输出到一个名为out.txt的文件中


应用程序从命令模式运行完美。我需要将它变成一个Web应用程序,以便它可以在任何地方在浏览器中运行。

我尝试过cherrypy和django教程,但是没有成功,因为我对这个领域是全新的。可以帮助我们一些步骤继续进行。


非常感谢您的帮助。

提前致谢!

Susanne

解决方案

听起来你需要的是一个cgi脚本。这很幸运很简单。


这里有一个模板:

展开 | 选择 | 换行 | 行号


我只是要为Kudos的答案添加一些内容。


你的python脚本应该生成的输出应该是HTML,因为它正在运行要在Web浏览器中显示。


我建议您在当前逻辑和HTML之间保持清晰的分离,否则它可能会非常混乱。


创建一个构建HTML的函数,这样就可以了r了解发生了什么。


例如:

展开 | 选择 | 换行 | 行号


< blockquote>这是非常真实的!但是不要忘记这一部分:

展开 | 选择 | Wrap | 行号


Hi, I am very new to the python web applications. can some one help.
I have a python application with some functions in it.

1) The application reads an input file ( say, IN.txt).
the IN.txt file contains names of three other files( x.dat, y.txt, z.dat) that are
in the same directory.

2) then the application reads the data in the files x.dat, y.txt, z.dat and performs some calculations.

3) outputs the results in a file called out.txt

The application is running perfectly from command mode. I need to make it a web application so that it can be run in a browser from anywhere.
I tried with cherrypy and django tutorials, but could not succeed, as i am completely new to this field. can some one help with steps to proceed.

Your help is highly appreciated.
Thanks in advance!
Susanne

解决方案

It sound like what you need is a cgi-script. This is luckily quite simple.

here is a template:

Expand|Select|Wrap|Line Numbers


I''m just going to add a bit to Kudos''s answer.

The output that your python script should produce should be HTML since it''s going to be displayed in a web browser.

I would recommend keeping a clear separation between your current logic and the HTML or else it can get very messy to read.

Make a function that builds the HTML so that it''s easier to understand what''s going on.

For example:

Expand|Select|Wrap|Line Numbers


That is very true! however do not forget this part:

Expand|Select|Wrap|Line Numbers


这篇关于为python应用程序创建一个Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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