为了账号安全,请及时绑定邮箱和手机立即绑定

http://localhost:8080/article访问时报“AttributeError: No template named hello2”

下面是我写的代码,烦请帮忙看下是哪里的问题?
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.模板目录
http://img1.sycdn.imooc.com//619c922b00014d5312050295.jpg

正在回答

举报

0/150
提交
取消

http://localhost:8080/article访问时报“AttributeError: No template named hello2”

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信