[web2py] Re: IMPORTANT - WEB2PY CONSULTING
Hello sir i have tried all i could, still having errors in the reddit clone application. everything works fine except when i implemented {{=author(user_id)}} 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 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':}} {{=category.name.title()}} {{=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':}} {{=category.name.title()}} {{=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:}} {{=author(user_id)}} {{pass}} {{for post in rows:}} {{=post.votes}} {{ =A(post.title,_href=post.url) if post.url else post.title}} {{=A('comments', _href=URL('view_post', args= post.id))}} {{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',
[web2py] Re: NameError: name 'category' is not defined (reddit clone application)
Pls I am waiting for reply. pls anyone help? On Monday, August 22, 2016 at 2:58:08 PM UTC+1, Annexx Xaar wrote: > > Hello sir i have tried all i could, still having errors in the reddit > clone application. > everything works fine except when i > implemented {{=author(user_id)}} 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 > 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':}} > {{=category.name.title()}} > {{=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':}} > {{=category.name.title()}} > {{=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:}} > {{=author(user_id)}} > {{pass}} > > > {{for post in rows:}} > > > {{=post.votes}} > {{ =A(post.title,_href=post.url) if post.url else > post.title}} > {{=A('comments', _href=URL('view_post', args= > post.id))}} > > > > {{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('cate
[web2py] Re: reddit clone - foreign key constraint failed
Examine ur controller, its likely from the controller, i had similar issue. On Friday, November 27, 2015 at 12:43:33 AM UTC+1, Carlos Zenteno wrote: > > Coming back to web2py again. > > I am going through Massimo's videos and doing the reddit clone. > > I use appadmin to add users and categories and all is fine. > > then I proceed to add posts manually, without using 'populate' > > I get the following ticket/error: > > > Error ticket for "reddit" > Ticket ID > > 127.0.0.1.2015-11-26.17-32-59.dcabdfff-16d6-4813-98ff-8992bd6d3370 > foreign key constraint failed > Version > > web2py™ Version 2.12.3-stable+timestamp.2015.08.19.00.18.03 > Python Python 2.7.2+: /usr/bin/python (prefix: /usr) > > > I have deleted the database a couple of times and let it regenerate again > wiith no luck. Also the post table, same thing. Don't know what to do > now... > any pointers? > > > -- 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.
[web2py] NameError: name 'category' is not defined (reddit clone application)
Hello sir i have tried all i could, still having errors in the reddit clone application. everything works fine except when i implemented {{=author(user_id)}} 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 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':}} {{=category.name.title()}} {{=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':}} {{=category.name.title()}} {{=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:}} {{=author(user_id)}} {{pass}} {{for post in rows:}} {{=post.votes}} {{ =A(post.title,_href=post.url) if post.url else post.title}} {{=A('comments', _href=URL('view_post', args= post.id))}} {{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',
[web2py] reddit clone application name 'category' is not defined
Hello sir i have tried all i could, still having errors in the reddit clone application. everything works fine except when i implemented {{=author(user_id)}} 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 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':}} {{=category.name.title()}} {{=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':}} {{=category.name.title()}} {{=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:}} {{=author(user_id)}} {{pass}} {{for post in rows:}} {{=post.votes}} {{ =A(post.title,_href=post.url) if post.url else post.title}} {{=A('comments', _href=URL('view_post', args=post.id))}} {{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',