Probably very naive question from new user

114 views
Skip to first unread message

c...@isbd.net

unread,
Jan 31, 2016, 7:48:39 AM1/31/16
to web...@googlegroups.com
I have just installed web2py on an xubuntu system (latest stable
download rather then from the Ubuntu repository). That's all OK and I
can run web2py.py and, after entering a password, the 'Welcome' page
appears in my browser.

I'm fairly experienced with the LAMP admin side of things so that was
very easy. I also use Python as my language of choice for utility
scripts etc. so I know the basics of Python.

However I'm still rather stumped trying to actually get to produce
something in my web browser using web2py.

I have been looking at the simple examples page:-

http://www.web2py.com/examples/default/examples

... and that's where I get stuck.

The first (minor) problem is that it says something like "In
controller: simple_examples.py" above each example. On my system
simple_examples.py is in <web2py>/applications/examples/controllers/simple_examples.py
which isn't quite what it says.

... but more importantly what do I do to actually produce the pages
the examples are supposed to create?



Then (though this is maybe trying to run before I can walk as I can't
really understand the simplest examples) when you get down to the
database examples (which is what I'm particularly interested in) there
are various oddities:-

The 'try it here' link suddenly disappears, so I can't see what's
supposed to happen.

The directory <web2py>/applications/examples/databases is empty

There are two db.py files in my installation (I think one is to do
with the admin system, but still it's confusing)


--
Chris Green
·

c...@isbd.net

unread,
Jan 31, 2016, 8:33:38 AM1/31/16
to web...@googlegroups.com
c...@isbd.net wrote:
> Then (though this is maybe trying to run before I can walk as I can't
> really understand the simplest examples) when you get down to the
> database examples (which is what I'm particularly interested in) there
> are various oddities:-
>
> The 'try it here' link suddenly disappears, so I can't see what's
> supposed to happen.
>
> The directory <web2py>/applications/examples/databases is empty
>
> There are two db.py files in my installation (I think one is to do
> with the admin system, but still it's confusing)
>
... and the link from the Simple Examples which says "You can find
more examples of the web2py Database Abstraction Layer here" doesn't
take you to any more examples, or none that I could see.

--
Chris Green
·

Anthony

unread,
Jan 31, 2016, 8:42:10 AM1/31/16
to web...@googlegroups.com

The first (minor) problem is that it says something like "In
controller: simple_examples.py" above each example.  On my system
simple_examples.py is in <web2py>/applications/examples/controllers/simple_examples.py
which isn't quite what it says.

Not sure what you mean. According to the documentation, controller files go in the application's /controllers folder, and that is where the simple_examples.py controller file is found.
 
...  but more importantly what do I do to actually produce the pages
the examples are supposed to create?

The examples are already created in the "examples" application. There are several controllers as well as a set of views associated with the various actions. If you wanted to create them from scratch, you could just duplicate the code from the "examples" app in your own app (i.e., create your own controller and view files and fill them in with the relevant code).

Rather than trying to learn everything from the examples page, you should probably proceed to the book.
 
Then (though this is maybe trying to run before I can walk as I can't
really understand the simplest examples) when you get down to the
database examples (which is what I'm particularly interested in) there
are various oddities:-

    The 'try it here' link suddenly disappears, so I can't see what's
    supposed to happen.

The database examples don't have links because we don't want to allow database writes in the online examples. You can try them in your local installation, though.
 
    The directory <web2py>/applications/examples/databases is empty

You don't have to worry about that. The first time a request is made to the app and the model files are executed, some files will be created there (assuming migrations are not turned off). The /databases folder stores metadata used for migrations (and is typically where the SQLite database file is stored when using SQLite).
 
    There are two db.py files in my installation (I think one is to do
    with the admin system, but still it's confusing)

Every application has a separate folder within the /applications folder, and each application has its own models, views, and controllers, etc. So yes, the admin app has its own db.py model file.

Again, you're not intended to understand everything by reviewing that single examples page and looking at the folders -- please read the book.

Anthony

Anthony

unread,
Jan 31, 2016, 8:44:03 AM1/31/16
to web2py-users

... and the link from the Simple Examples which says "You can find
more examples of the web2py Database Abstraction Layer here" doesn't
take you to any more examples, or none that I could see.

It takes you to an entire chapter of the book on the Database Abstraction Layer -- with lots of examples.

Anthony

c...@isbd.net

unread,
Jan 31, 2016, 9:16:27 AM1/31/16
to web...@googlegroups.com
Anthony <abas...@gmail.com> wrote:
> [-- multipart/alternative, encoding 7bit, 48 lines --]
>
> [-- text/plain, encoding 7bit, charset: UTF-8, 23 lines --]
> Layer -- with *lots* of examples.
>
Yes, I followed it to the book but couldn't see any examples there.
Let me try again.... No, sorry, I can't see any. I mean I don't
really count things like the following as examples:-

You can also use explicit quoting of SQL entities at DAL level. It
works transparently so you can use the same names in python and in the
DB schema.
ignore_field_case = Trueentity_quoting = True

Here is an example:

db = DAL('postgres://...', ...,ignore_field_case=False,
entity_quoting=True)

db.define_table('table1', Field('column'), Field('COLUMN'))

print db(db.table1.COLUMN != db.table1.column).select()

I mean, that's just a code snippet to illustrate a point. What I was
hoping for was complete chunks of code that I could load/install and
see the result as a web page.

--
Chris Green
·

c...@isbd.net

unread,
Jan 31, 2016, 9:33:36 AM1/31/16
to web...@googlegroups.com
Anthony <abas...@gmail.com> wrote:
> [-- multipart/alternative, encoding 7bit, 161 lines --]
>
> [-- text/plain, encoding 7bit, charset: UTF-8, 77 lines --]
>
>
> >
> >
> > The first (minor) problem is that it says something like "In
> > controller: simple_examples.py" above each example. On my system
> > simple_examples.py is in
> > <web2py>/applications/examples/controllers/simple_examples.py
> > which isn't quite what it says.
> >
>
> Not sure what you mean. According to the documentation, controller files go
> in the application's /controllers folder, and that is where the
> simple_examples.py controller file is found.
>
OK, it just isn't clear when you go straight to the simple examples
page.

>
> > ... but more importantly what do I do to actually produce the pages
> > the examples are supposed to create?
> >
>
> The examples are already created in the "examples" application. There are
> several controllers as well as a set of views associated with the various
> actions. If you wanted to create them from scratch, you could just
> duplicate the code from the "examples" app in your own app (i.e., create
> your own controller and view files and fill them in with the relevant code).
>
> Rather than trying to learn everything from the examples page, you should
> probably proceed to the book.
>
Yes, I'm beginning to realise that, however I was expecting 'simple
examples' to allow me to create something that worked that I could
look at to see how it all hangs together.

The book *does* have a Simple Examples section in Chapter Three and
that's maybe where I should have started. I was misled by the Simple
Examples link from the web site.

>
> > Then (though this is maybe trying to run before I can walk as I can't
> > really understand the simplest examples) when you get down to the
> > database examples (which is what I'm particularly interested in) there
> > are various oddities:-
> >
> > The 'try it here' link suddenly disappears, so I can't see what's
> > supposed to happen.
> >
>
> The database examples don't have links because we don't want to allow
> database writes in the online examples. You can try them in your local
> installation, though.
>
OK, would be nice to be told that. :-)


>
> > The directory <web2py>/applications/examples/databases is empty
> >
>
> You don't have to worry about that. The first time a request is made to the
> app and the model files are executed, some files will be created there
> (assuming migrations are not turned off). The /databases folder stores
> metadata used for migrations (and is typically where the SQLite database
> file is stored when using SQLite).
>
OK

>
> > There are two db.py files in my installation (I think one is to do
> > with the admin system, but still it's confusing)
> >
>
> Every application has a separate folder within the /applications folder,
> and each application has its own models, views, and controllers, etc. So
> yes, the admin app has its own db.py model file.
>
> Again, you're not intended to understand everything by reviewing that
> single examples page and look at the folders -- please read the book.
>
Yes, OK, I'm now reading the book. I think there should be stronger
pointers towards it. :-)

--
Chris Green
·

Anthony

unread,
Jan 31, 2016, 1:10:09 PM1/31/16
to web2py-users
> It takes you to an entire chapter of the book on the Database Abstraction
> Layer -- with *lots* of examples.
>
Yes, I followed it to the book but couldn't see any examples there.
Let me try again....   No, sorry, I can't see any.  I mean I don't
really count things like the following as examples:-

    You can also use explicit quoting of SQL entities at DAL level. It
    works transparently so you can use the same names in python and in the
    DB schema.
    ignore_field_case = Trueentity_quoting = True

    Here is an example:

    db = DAL('postgres://...', ...,ignore_field_case=False,
    entity_quoting=True)

    db.define_table('table1', Field('column'), Field('COLUMN'))

    print db(db.table1.COLUMN != db.table1.column).select()

I mean, that's just a code snippet to illustrate a point.  What I was
hoping for was complete chunks of code that I could load/install and
see the result as a web page.

We can't help what you were hoping for, but the link says, "You can find more examples of the web2py Database Abstraction Layer here." Indeed, there are plenty of examples in that chapter, including complete working chunks of code (specifically related to the DAL). Nothing was promised about complete model-view-controller examples (which have already been provided in the examples app).

Anthony

unread,
Jan 31, 2016, 1:20:33 PM1/31/16
to web2py-users

> Rather than trying to learn everything from the examples page, you should
> probably proceed to the book.
>  
Yes, I'm beginning to realise that, however I was expecting 'simple
examples' to allow me to create something that worked that I could
look at to see how it all hangs together.

The examples you see on that page are included in the "examples" app that comes with web2py, so you can easily play around with the examples. And you can indeed copy and paste the code from the examples to create something that works. Not sure what the problem is.
 
> Again, you're not intended to understand everything by reviewing that
> single examples page and look at the folders -- please read the book.
>
Yes, OK, I'm now reading the book.  I think there should be stronger
pointers towards it.  :-)

I don't know how you got to the examples page, but assuming it was from the link on the home page, the link to the "manual" is just three words to the right. The home page also includes a prominent image linking to the book. Finally, there is a "Docs & Resources" link in the main site navigation, and the first link on that page (the only one in bold) is for the book. Did you really have a hard time finding the book?

Anthony

黄祥

unread,
Jan 31, 2016, 5:11:38 PM1/31/16
to web2py-users
perhaps you can learn a lot from web2py appliances or web2py slices :

best regards,
stifan

Ron Chatterjee

unread,
Jan 31, 2016, 6:30:22 PM1/31/16
to web2py-users
There are few videos on Vimeo. Good luck!

c...@isbd.net

unread,
Feb 1, 2016, 6:33:38 AM2/1/16
to web...@googlegroups.com
黄祥 <steve.van...@gmail.com> wrote:
>
> perhaps you can learn a lot from web2py appliances or web2py slices :
> http://www.web2py.com/appliances
> http://www.web2pyslices.com
>
Yes, thank you, appliances looks very useful. I think it was actually
something on web2pyslices.com that I found that lead me to investigate
web2py. There's a bigger 'hump' to get to understand than I was
expecting though (maybe 'hoping'). :-)

Thanks for all the help everyone, I hope I didn't come across too
negative, not intended.

--
Chris Green
·

jimbo

unread,
Feb 1, 2016, 1:58:44 PM2/1/16
to web2py-users
I found this useful as are other posts on the site.  http://www.pyguy.com/web2py/web2py-one-to-many-database-tutorial/

Oliver Holmes

unread,
Feb 7, 2016, 12:32:01 AM2/7/16
to web2py-users
Oh, yes. Those nice small tuts are really helpful.

Tom Campbell

unread,
Feb 10, 2016, 11:35:29 PM2/10/16
to web2py-users
www.pyguy.com has a few beginner-level tutorials that probably answer those questions
Reply all
Reply to author
Forward
0 new messages