下面是我写的代码,烦请帮忙看下是哪里的问题?
1.code.py
import web
import MySQLdb
import MySQLdb.cursors
render =web.template.render('templates')
urls = (
'/article', 'article',
'/index', 'index',
'/blog/\d+', 'blog',
'/(.*)', 'hello',
)
app = web.application(urls, globals())
class index:
def GET(self):
query = web.input()
return query
class blog:
def POST(self):
data = web.input()
return data
def GET(self):
return web.ctx.env
class hello:
def GET(self, name):
return render.hello2(name)
class article:
def GET(self):
conn = MySQLdb.connect(host='localhost', user='root', password='root', db='test', port=3306, cursorclass=MySQLdb.cursors.DictCursor)
cur = conn.cursor()
cur.execute('select * from articles')
r = cur.fetchall()
cur.close()
conn.close()
print(r)
return render.article(r)
if __name__ == "__main__": app.run()
2.hello2.html
$def with(name)
<html>
<head>
<title>hello</title>
</head>
<body>
<h1>POST</h1>
<form action="/blog/123" method="POST">
<input type="text" name="username" value="$name"/>
<input type="password" name="password" value=""/>
<input type="submit" value="submit">
</form>
</body>
</html>
3.article.html
$def with(r)
<html>
<head>
<meta charset="utf-8"/>
<title>article</title>
</head>
<body>
<h1>文章列表</h1>
<ul>
$for l in r:
<li>$l.get('aid') => $l.get('title')</li>
</ul>
</body>
</html>
4.模板目录