Why do I get a blank screen on view

53 views
Skip to first unread message

Maurice Waka

unread,
Jun 15, 2017, 12:03:54 AM6/15/17
to web2py-users
when trying to view posts created by author, i tried this piece of code on controller:
  1. option one:  replies = db(db.answers.posted_by==auth.user_id).select(orderby=~db.answers.posted_by,limitby=(0,10))
  2. option two where the author has two fields populated with information:
    1.  questions = db(db.answers.quest == auth.user_id).select()
    2.  replies  =  db(db.answers.report == auth.user_id).select()
With above options, i keep getting a blank screen., but messages are posted to the database
With this option below, i get to view all posts by not only the author's posts but by all authors logged. I want it private that ONLY the author can view his/her posts.
  • replies  =  db(db.answers).select()
  • return dict(replies=replies)
The code on the models is:

db.define_table('answers',
                Field('quest', 'text', 'reference auth_user'),
                Field('report', 'text', 'reference auth_user'),
                Field('posted_by','reference auth_user',readable=False,writable=False),
                auth.signature
                )


code on view.html:
  1. Option one: all authors posts are seen on view
{{for reply in replies:}}
{{=reply.quest}}
{{=reply.report.}}
{{pass}}
  1. Option two. gives a blank screen/view
{{for question in questions:}}
{{=question.quest}}
{{pass}}
{{for reply in replies:}}
{{=reply.reportt}}
{{pass}}


I don't know where am going wrong. Please assist
Kind regards 
 

Anthony

unread,
Jun 15, 2017, 12:25:14 AM6/15/17
to web2py-users
What is the value of auth.user_id? Are you sure there are records in the database whose "post_by" value is equal to it?

Maurice Waka

unread,
Jun 15, 2017, 1:48:51 AM6/15/17
to web...@googlegroups.com
Sorry. Am not sure about value of Auth.user_id

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/Msoj2qZO7RU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

黄祥

unread,
Jun 15, 2017, 2:08:25 AM6/15/17
to web2py-users
just an idea, why not put the default value for that fields?
e.g.
default = auth.user_id

best regards,
stifan

Anthony

unread,
Jun 15, 2017, 2:19:34 AM6/15/17
to web2py-users
On Thursday, June 15, 2017 at 1:48:51 AM UTC-4, Maurice Waka wrote:
Sorry. Am not sure about value of Auth.user_id

It is the id of the current logged in user. You can simply display it on the page or print it to the console to inspect it.

Anthony

Maurice Waka

unread,
Jun 15, 2017, 3:03:53 AM6/15/17
to web...@googlegroups.com
Thanks. Once logged in I'll fix it. 
Regards 

--

Maurice Waka

unread,
Jun 17, 2017, 7:24:42 AM6/17/17
to web...@googlegroups.com

db.define_table('answers',
                Field('quest', 'text', default =auth. user_id) ,
                Field('report', 'text', default =auth. user_id)
                auth.signature
                )

On default controller  :
  • replies  =  db(db.answers).select()
  • return dict(replies=replies)
With this I still have the same problem where all posts by logged in users are viewed instead of the specific ones by the default user. 
If I do this on default controller:
  1.  questions = db(db.answers.quest == auth.user_id).select()
  2.  replies  =  db(db.answers.report == auth.user_id).select()
I still get a blank screen. 

--

Anthony

unread,
Jun 17, 2017, 1:25:21 PM6/17/17
to web2py-users
auth.user_id is the id of the logged in user or None if the current user is not logged in. There is no "default" user. Unless the "quest" and "report" fields are sometimes set to None rather than an actual user id, your second set of queries will never return any results.

Anthony

Maurice Waka

unread,
Jun 20, 2017, 11:25:20 AM6/20/17
to web...@googlegroups.com
I did this:
replies = db().select(db.answers.ALL, orderby=auth.user.id)

could it be because am using the same local ip(127.0.0.8000) address when trying out different users and get the same result?

Anthony

unread,
Jun 20, 2017, 1:09:55 PM6/20/17
to web2py-users
On Tuesday, June 20, 2017 at 11:25:20 AM UTC-4, Maurice Waka wrote:
I did this:
replies = db().select(db.answers.ALL, orderby=auth.user.id)

orderby must be a Field object, not an integer value.
 

could it be because am using the same local ip(127.0.0.8000) address when trying out different users and get the same result?

auth.user is the user record of the currently logged in user. If you are logged in, then it will always be your user record.

Anthony
Reply all
Reply to author
Forward
0 new messages