忍者ブログ
[261]  [260]  [259]  [258]  [257]  [256]  [255]  [254]  [253]  [252]  [251
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

まずはHelloworldから

from webob import Request, Response #webObの読み込み

#htmlの定義
html = """
<html>
<head>
<title>test</title>
</head>
<body>
<h1>hello woard</h1>
</body>
</html>
"""
def application(environ, start_response):
    resp = Response(html)
    return resp(environ, start_response)
if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    port =8080
    server = make_server('',port,application)
    server.serve_forever()

で表示されました


次にON OFFのテスト

#webTest
from webob import Request, Response
html = """<h1> 結果:%d</h1>
<form method="post">
<input type="submit" name="button" value="たす">
<input type="submit" name="button" value="ひく">
</form>
"""
count= 0
class WebApp(object):
    def __call__(self, environ ,start_response):
        global html,count
        req=Request(environ)
        if req.path=='/':
            button = req.params.get('button','')
            if (button=='たす'):
                count=count + 1
            if (button=='ひく'):
                count = count -1
            resp = Response(html % count)
        else:
            resp = Response()
        return resp(environ, start_response)
application = WebApp()
if __name__== '__main__':
    from wsgiref.simple_server import make_server
    port=8080
    httpd= make_server('', port, application)
    print('Http on port %s.' % port)
    httpd.serve_forever()

数字がアップダウンします

拍手

PR
カレンダー
04 2025/05 06
S M T W T F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
フリーエリア
最新CM
[03/10 DORA]
最新TB
プロフィール
HN:
dorabu
性別:
非公開
バーコード
ブログ内検索
P R
忍者おまとめボタン
Copyright © ドラブーのアンドロイドとIoTなブログ All rights reserved. / Template by 四季. / Material by てんせん.

忍者ブログ [PR]