web2py manual entry for 3.3 An image blog does not work

40 views
Skip to first unread message

Bryan Nahrwold

unread,
Feb 14, 2018, 10:16:11 AM2/14/18
to web2py-users
I have downloaded Web2Py version 2.16.1-stable+timestamp.2017.11.14.05.54.25

I am working my way through the manual in section 3.3 An image blog.

The manual specifies to create the images project and replace ALL content in db.py with:

db = DAL("sqlite://storage.sqlite")

db.define_table('image',
   Field('title', unique=True),
   Field('file', 'upload'),
   format = '%(title)s')

db.define_table('post',
   Field('image_id', 'reference image'),
   Field('author'),
   Field('email'),
   Field('body', 'text'))

db.image.title.requires = IS_NOT_IN_DB(db, db.image.title)
db.post.image_id.requires = IS_IN_DB(db, db.image.id, '%(title)s')
db.post.author.requires = IS_NOT_EMPTY()t say to do anything but replace
db.post.email.requires = IS_EMAIL()
db.post.body.requires = IS_NOT_EMPTY()

db.post.image_id.writeable = db.post.image_id.readable = False

Until I make this change I can click on the Database Administration link for this app and go to the listing of database files for this application.
Once I make this change and click the Database Administration link, I get :the ticket with the error listing below. Now I have tied both copying the new db.py content and typing it in, multiple times. The manual does not say to do anything but replace the text, save, and then click the images application data base administration link. It always errors with:

Error ticket for "images"

Ticket ID

127.0.0.1.2018-02-13.15-53-20.c0e98cc5-8b46-4b1b-af35-538c69d19a9f

<type 'exceptions.NameError'> name 'configuration' is not defined

Version

web2py™ Version 2.16.1-stable+timestamp.2017.11.14.05.54.25
Python Python 2.7.9: C:\web2py_win\web2py\web2py.exe (prefix: )

Traceback

1.
2.
3.
4.
5.
6.
7.
Traceback (most recent call last):
File "C:\web2py_win\web2py\gluon\restricted.py", line 219, in restricted
exec(ccode, environment)
File "C:/web2py_win/web2py/applications/images/models/menu.py", line 16, in <module>
if not configuration.get('app.production'):
NameError: name 'configuration' is not defined

Error snapshot help

<type 'exceptions.NameError'>(name 'configuration' is not defined)

inspect attributes

Frames

  • File C:\web2py_win\web2py\gluon\restricted.py in restricted at line 219 code arguments variables

  • File C:\web2py_win\web2py\applications\images\models\menu.py in <module> at line 16 code arguments variables

    Function argument list

    ()

    Code listing
    11.
    12.
    13.
    14.
    15.
    16.

    17.
    18.
    19.
    20.

    # ----------------------------------------------------------------------------------------------------------------------
    # provide shortcuts for development. you can remove everything below in production
    # ----------------------------------------------------------------------------------------------------------------------

    if not configuration.get('app.production'):

    _app = request.application
    response.menu += [
    (
    T('My Sites'), False, URL('admin', 'default', 'site')),
    (
    T('This App'), False, '#', [
    Variables
    configuration undefined

In file: C:\web2py_win\web2py\applications\images\models\menu.py

1.
<code object <module> at 03B9D890, file "C:\web2py_win\web2py\applications\images\models\menu.py", line 9>

Powered by web2py™ created by Massimo Di Pierro ©2007-2018 - Admin language

Anthony

unread,
Feb 14, 2018, 10:47:57 AM2/14/18
to web2py-users
Good catch. The problem is the new default version of db.py creates a "configuration" object, which is subsequently referenced in the menu.py model file.

Anyway, there is no need to completely replace the contents of db.py -- just add the content shown, except you don't need the db = DAL(...) line.

Anthony

Bryan Nahrwold

unread,
Feb 14, 2018, 3:00:14 PM2/14/18
to web2py-users
Thanks, Anthony. That works.

Bryan Nahrwold

unread,
Feb 14, 2018, 3:04:54 PM2/14/18
to web2py-users
However, it does not work unless I include the linne you said to omit:

db = DAL("sqlite://storage.sqlite")

Powered by web2py™ created by Massimo Di Pierro ©2007-2018 - Admin language

Anthony

unread,
Feb 14, 2018, 3:42:10 PM2/14/18
to web2py-users
On Wednesday, February 14, 2018 at 3:04:54 PM UTC-5, Bryan Nahrwold wrote:
However, it does not work unless I include the linne you said to omit:

db = DAL("sqlite://storage.sqlite")

If you are starting with the scaffolding app, it should already include:

configuration = AppConfig(reload=True)

if not request.env.web2py_runtime_gae:
   
# ---------------------------------------------------------------------
   
# if NOT running on Google App Engine use SQLite or other DB
   
# ---------------------------------------------------------------------
    db
= DAL(configuration.get('db.uri'),
             pool_size
=configuration.get('db.pool_size'),
             migrate_enabled
=configuration.get('db.migrate'),
             check_reserved
=['all'])

So, you should not need to redefine the db object. Do you not have the above code in your db.py, or was it generating an error?

Anthony

Reply all
Reply to author
Forward
0 new messages