Hello sir i have tried all i could, still having errors in the reddit clone application. everything works fine except when i implemented <h2>{{=author(user_id)}}</h2> under list_posts_by_votes.html the errors blows when i click on the author of a comment. it does not dislay the author's name as it showed in the toturial video.
here's it 1. 2. 3. 4. 5. 6. Traceback (most recent call last): File "C:\Users\nsikan\Desktop\web2py\gluon\restricted.py", line 227, in restricted exec ccode in environment File "C:\Users\nsikan\Desktop\web2py\applications\mydream\views\default/list_posts_by_votes.html", line 117, in <module> NameError: name 'category' is not defined here's deault.py POSTS_PER_PAGE = 10 def get_category(): category_name = request.args(0) category = db.category(name = category_name) if not category: session.flash = 'page has not been created' redirect(URL('index')) return category def index(): rows = db(db.category).select() return locals() def create_post(): category = get_category() db.post.category.default = category.id form = SQLFORM(db.post).process(next='view_post/[id]') return locals() def edit_post(): id = request.args(0, cast=int) form = SQLFORM(db.post, id).process(next='view_post/[id]') return locals() def list_posts_by_datetime(): response.view='default/list_posts_by_votes.html' category = get_category() page = request.args(1, cast=int, default=0) start = page * POSTS_PER_PAGE stop = start + POSTS_PER_PAGE rows = db(db.post.category==category.id).select(orderby=~db.post.created_on, limitby=(start, stop)) return locals() def list_posts_by_votes(): category = get_category() page = request.args(1, cast=int, default=0) start = page * POSTS_PER_PAGE stop = start + POSTS_PER_PAGE rows = db(db.post.category==category.id).select(orderby=~db.post.votes, limitby=(start, stop)) return locals() def list_posts_by_author(): response.view='default/list_posts_by_votes.html' user_id = request.args(0, cast=int) page = request.args(1, cast=int, default=0) start = page * POSTS_PER_PAGE stop = start + POSTS_PER_PAGE rows = db(db.post.created_by==user_id).select(orderby=~db.post.created_on, limitby=(start, stop)) return locals() def view_post(): id = request.args(0, cast=int) post = db.post(id) or redirect(URL('index')) comments = db(db.comm.post==post.id).select(orderby=~db.comm.created_on) ##TODO return locals() def vote_callback(): id = request.args(0, cast=int) direction = request.args(1) ##TODO return locals() def comm_vote_callback(): id = request.args(0, cast=int) direction = request.args(1) ##TODO return locals() here's lists_posts_by_votes.html {{extend 'layout.html'}} {{if request.function=='list_posts_by_votes':}} <h2>{{=category.name.title()}}</h2> {{=A('sort by datetime', _class='btn', _href=URL('list_posts_by_datetime', args=category.name))}} {{=A('post a new link', _class='btn btn-primary', _href=URL('create_post', args=category.name))}} {{elif request.function=='list_posts_by_datetime':}} <h2>{{=category.name.title()}}</h2> {{=A('sort by votes', _class='btn', _href=URL('list_posts_by_votes', args=category.name))}} {{=A('post a new link', _class='btn btn-primary', _href=URL('create_post', args=category.name))}} {{else:}} <h2>{{=author(user_id)}}</h2> {{pass}} <hr/> {{for post in rows:}} <div class="well"> <table> <tr><td><span class="votes">{{=post.votes}} </span></td><td><strong> {{ =A(post.title,_href=post.url) if post.url else post.title}}</strong></td></tr> <tr><td></td><td>{{=A('comments', _href=URL('view_post', args=post.id))}}</td></tr> </table> </div> {{pass}} {{if page>0:}} {{=A('previous', _class='btn', _href=URL(args=(category.name, page-1)))}} {{pass}} {{if len(rows)>=10:}} {{=A('next', _class='btn', _href=URL(args=(category.name, page+1)))}} {{pass}} here's db1.py # -*- coding: utf-8 -*- # -*- coding: utf-8 -*- db.define_table('category', Field('name', requires=(IS_SLUG(), IS_LOWER(),IS_NOT_IN_DB(db, 'category.name')))) db.define_table('post', Field('category', 'reference category', writable=False, readable=False), Field('title', 'string', requires=IS_NOT_EMPTY()), Field('url', requires=IS_EMPTY_OR(IS_URL())), Field('body', 'text', requires=IS_NOT_EMPTY()), Field('votes', 'integer',default=0 , readable=False, writable=False), auth.signature)#created_on, created_by, modified_by, modified_on, is_active db.define_table('vote', Field('post', 'reference post'), Field('score', 'integer', default=+1), auth.signature) db.define_table('comm', Field('post', 'reference post'), Field('parent_comm', 'reference comm'), Field('votes', 'integer' ), Field('body', 'text', requires=IS_NOT_EMPTY()), auth.signature) db.define_table('comm_vote', Field('comm', 'reference comm'), Field('votes', 'integer',default=+1), auth.signature) def author(id): if id is None: return "Anonymous" else: user = db.auth_user(id) return A('%(first_name)s %(last_name)s' % user, _href=URL('list_posts_by_author', args=user.id)) from gluon.contrib.populate import populate if db(db.auth_user).count()<3: populate(db.auth_user, 100) db.commit() if db(db.post).count()<3: populate(db.post, 500) db.commit() if db(db.comm).count()<3: populate(db.comm, 1000) db.commit() please help me. I'm stuck. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.