This document explains how to use Eclipse with web2py.
It was tested on the cookbook example.
The only notable things so far are:
__init__.py
modules where you want to be able to import things
from your own code. Only models have been tested so far.One gotcha is make sure you choose the correct case:
return dict(records=SQLTABLE(records))
There are two SQLTABLE: SQLTABLE and SQLTable. The lower case one does not need to exposed since it is not intended to be instantiated by the user. The upper case one is being used to output html, and is the one we want. As Python is case sensitive, you would not get the expected outcome if you choose the wrong item.
To let Eclipse know about variables being passed into the controller at runtime, you can do the following
global db
global request
global session
global reqponse
This will remove the warnings about them being undefined.
Typing redirect
will get the correct import and you can use it normally.
To use session
, request
and (theoretically but untried) response
with hints and code completion, you can use this code:
req=Request()
req=request
ses=Session()
ses=session
resp=Response()
resp=response
as you type those you will get the imports for these objects as well:
from gluon.globals import Request
from gluon.globals import Session
from gluon.globals import Response
Then you can use req
as you would with request
but with code hinting, etc., and ses
for session
, and resp
for response
. If anyone knows a better way to cast request
, session
, and response
as their correct types, please do leave a comment.
Code hints and completion in Eclipse is very nice and provide a valid alternative to the web2py built-in editor. Unfortunately you do not get the code hints unless you also import the statement. If you choose to keep "Do auto imports?" checked, imports from your own models, controllers, etc., may throw errors. You can review those and delete the undesired imports. Or perhaps simply use it as a memory aid and keep typing without selecting the object so as to not trigger the auto import.
Please note that this is still a work in progress!