上記の index.html を再度使用する
Example 4. test02.py
# -*- coding:utf-8 -*-
# http://localhost:8080/?name=hoge とすると name が指定される
import web
urls = (
'/', 'index'
)
app = web.application(urls, globals())
render = web.template.render('templates/')
class index:
def GET(self):
i = web.input(name=None)
return render.index(i.name)
if __name__ == "__main__": app.run()
実行
> python test02.pyhttp://localhost:8080/ にアクセスすると Hello, world! と表示される
http://localhost:8080/?name=hoge としてアクセスすると I just wanted to say hello to hoge. と表示される
URL の別階層として表示
index.html を再び使用する
Example 5. test03.py
# -*- coding:utf-8 -*-
# http://localhost:8080/hoge とすると name が指定される
import web
urls = (
'/(.*)', 'index'
)
app = web.application(urls, globals())
render = web.template.render('templates/')
class index:
def GET(self, name):
return render.index(name)
if __name__ == "__main__": app.run()
実行
> python test03.pyhttp://localhost:8080/ にアクセスすると Hello, world! と表示される
http://localhost:8080/hoge としてアクセスすると I just wanted to say hello to hoge. と表示される
0 件のコメント:
コメントを投稿