python怎么输出结果,我如何使用python打印输出到html页面?

I want user to enter a sentence then I break up that sentence into a list. I got the html page down but i have trouble passing that sentence to python.

How do I properly send the user input to be processed by python and output it to a new page?

解决方案

There are many Python web frameworks. For example, to break up a sentence using bottle:

break-sentence.py:

#!/usr/bin/env python

from bottle import request, route, run, view

@route('/', method=['GET', 'POST'])

@view('form_template')

def index():

return dict(parts=request.forms.sentence.split(), # split on whitespace

show_form=request.method=='GET') # show form for get requests

run(host='localhost', port=8080)

And the template file form_template.tpl that is used both to show the form and the sentence parts after processing in Python (see index() function above):

Break up sentence

%if show_form:

Input a sentence to break up

%else:

Sentence parts:

%for part in parts:

{{ part }}

%end

%end

request.forms.sentence is used in Python to access user input from field.

To try it you could just download bottle.py and run:

$ python break-sentence.py

Bottle server starting up (using WSGIRefServer())...

Listening on http://localhost:8080/

Hit Ctrl-C to quit.

Now you can visit http://localhost:8080/.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值