Skip to content

Instantly share code, notes, and snippets.

@aabril
Created February 2, 2012 13:00
Show Gist options
  • Select an option

  • Save aabril/1723355 to your computer and use it in GitHub Desktop.

Select an option

Save aabril/1723355 to your computer and use it in GitHub Desktop.
standalone web2py environment
'''
this snippet is used to load a web2py environment
you must install web2py (so gluon.*) from pyeggs : "pip install web2py"
it will read your db.py models from the same directory
'''
# web2py env
from gluon.shell import exec_environment
import MySQLdb
from gluon import DAL, Field
from gluon.template import render
from gluon.dal import MySQLAdapter
if not (MySQLAdapter.driver): MySQLAdapter.driver = MySQLdb
welcome = exec_environment('db.py')
db = welcome.db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment