0
view
#show.html
{{extend 'layout.html'}}
<h1>{{=page.title}}</h1>
[ {{=A('edit', _href=URL('edit', args=request.args))}} ]<br />
{{=MARKMIN(page.body)}}
<h2>Comments</h2>
{{for post in comments:}}
  <p>{{=db.auth_user[post.created_by].first_name}} on {{=post.created_on}}
     says <i>{{=post.body}}</i></p>
{{pass}}
<h2>Post a comment</h2>
{{=form}}

#controller
#default.py
def user():
    return dict(form=auth())
@auth.requires_login()
def index():
    pages = db().select(db.course.id,db.course.title,db.course.Instructor,orderby=db.course.title)
    return dict(pages=pages)
@auth.requires_login()
def createcourse():
     """creates a new empty wiki page"""
     form = SQLFORM(db.course).process(next=URL('index'))
     return dict(form=form)
def show():
     """shows a wiki page"""
     this_page = db.course(request.args(0,cast=int)) or redirect(URL('index'))
     db.post.course_id.default = this_page.id
     form = SQLFORM(db.post).process() if auth.user else None
     pagecomments = db(db.post.course_id==this_page.id).select()
     return dict(page=this_page, comments=pagecomments, form=form)

#model
#db.py
db = DAL("sqlite://storage.sqlite")
from gluon.tools import Auth
auth = Auth(db)
auth.define_tables(username=True)
db.define_table('course',
   Field('title', unique=True),
   Field('Instructor','text', unique=True),
   Field('Dateofcoursecreation','datetime'),
                Field('Courseid'),
   format = '%(title)s')

db.define_table('post',
    Field('course_id'),
    Field('body', 'text'),
    Field('created_on', 'datetime', default=request.now),
    Field('created_by', 'reference auth_user', default=auth.user_id))

#ticket issued

Error ticket for "courseapp"
Ticket ID

127.0.0.1.2016-03-16.20-55-17.d72cc1b2-28ab-4aea-be40-a372034830a5
<type 'exceptions.AttributeError'>
Version
web2py™     Version 2.13.4-stable+timestamp.2015.12.26.04.59.39
Python  Python 2.7.6: /usr/bin/python (prefix: /usr)
Traceback

1.
2.
3.
4.
5.
6.
7.
8.



Traceback (most recent call last):
  File "/home/nikhil/Downloads/web2py/gluon/restricted.py", line 227, in restricted
    exec ccode in environment
  File "/home/nikhil/Downloads/web2py/applications/courseapp/views/default/show.html", line 79, in <module>
  File "/home/nikhil/Downloads/web2py/gluon/packages/dal/pydal/objects.py", line 90, in __getattr__
    raise AttributeError
AttributeError

Error snapshot help

<type 'exceptions.AttributeError'>()

inspect attributes
Frames

    File /home/nikhil/Downloads/web2py/gluon/restricted.py in restricted at line 227 code arguments variables

    File /home/nikhil/Downloads/web2py/applications/courseapp/views/default/show.html in <module> at line 79 code arguments variables

    File /home/nikhil/Downloads/web2py/gluon/packages/dal/pydal/objects.py in __getattr__ at line 90 code arguments variables
    Function argument list

    (self=<Row {'title': 'maths', 'Dateofcoursecreation': ... 'Instructor': 'indranil chakrabarty', 'id': 1L}>, k='body')
    Code listing

    85.
    86.
    87.
    88.
    89.
    90.

    91.
    92.
    93.
    94.




        def __getattr__(self, k):
            try:
                return self.__getitem__(k)
            except KeyError:
                raise AttributeError


        def __copy__(self):
            return Row(self)

    Variables
    builtinAttributeError   <type 'exceptions.AttributeError'>

Please can anyone say where is the mistake?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
vanquishers
  • 358
  • 1
  • 3
  • 18
  • In the ticket, which line is identified as 79 in the view (note, it won't be line 79 in the template file, but line 79 after the view has been parsed into Python code, which should be shown in the ticket)? Presumably one of the field names you attempt to access in the view is incorrect (either misspelled or not part of the model). Might also help if you show your model code. – Anthony Mar 16 '16 at 16:13

1 Answers1

0

{{=MARKMIN(page.body)}} refers to an attribute called body, which does not exist on the table: course. This is the reason you see the error.

Kiran Subbaraman
  • 353
  • 4
  • 13