python web.py
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python web.py相关的知识,希望对你有一定的参考价值。
import web
urls=(
"*/(.+)","index"
)
app=web.application(urls,globals())
session = web.session.Session(app,web.session.DiskStore('sessions'),initializer={'count':0,'login':0,'name':''})
render=web.template.render('templates')
class index:
def GET(self):
name = ''
players = 'none'
playerList = []
if session.get('login')==1:
name = session.name
return render.index(name,playerList)
'''
in index.html
...
$def with (name,playerList)
...
<body>
$if name != '':
Hello <b>$name</b> !<br/>
Current players : [
$for player in playerList:
$player ,
]
$else:
Please login!
...
</body>
'''
import web
import json
class index:
def GET(self):
pyDict = {'one':1,'two':2}
web.header('Content-Type', 'application/json')
return json.dumps(pyDict)
以上是关于python web.py的主要内容,如果未能解决你的问题,请参考以下文章
python--web.py使用
Python之Web2py框架使用
Python Web2py 初试水
Python简单Web框架web.py实例hello world
python 3.x上安裝web.py
python web.py