On Thursday, August 31, 2017 at 8:05:51 AM UTC-7, Anthony wrote:
>
> Here is a variation of something I use in Jupyter notebook:
>
> import os
> import gluon.shell
> from gluon.settings import global_settings
> from gluon.storage import Storage
>
> def web2py_environment(app, controller=None, web2py_path=os.getcwd()):
> # Update global_settings.
> global_settings.gluon_parent = global_settings.applications_parent =
> web2py_path
> global_settings.cmd_options = Storage(shell=True) # for code that
> tests for shell
> with open(os.path.join(web2py_path, 'VERSION'), 'rb') as version_info:
> global_settings.web2py_version = version_info.read().split()[-1].
> strip()
> # Create the web2py environment.
> environment = gluon.shell.env(app, import_models=True, c=controller,
> dir=os.path.join(web2py_path, 'applications', app))
> folder = environment['request'].folder
> if controller:
> pyfile = os.path.join(folder, 'controllers', controller + '.py')
> if os.path.isfile(pyfile):
> execfile(pyfile, environment)
> globals().update(**environment)
>
> In your shell, import the above function and call:
>
> web2py_environment('yourapp', 'yourcontroller')
>
> Note, if the web2py folder is not the current working directory, you will
> need to explicity specify the web2py path (though you could certainly hard
> code that for your system rather than specifying it explicitly in the call).
>
> You can simplify the above code a bit if you don't need to add a
> controller to the environment, and updating those global settings isn't
> strictly necessary to get a working environment.
>
Cool, that seems to work nicely, thanks!
--
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 the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.