Skip to content

Instantly share code, notes, and snippets.

@kkappel
Forked from aabril/web2py_env.py
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save kkappel/65c6b83ee805cb936be0 to your computer and use it in GitHub Desktop.

Select an option

Save kkappel/65c6b83ee805cb936be0 to your computer and use it in GitHub Desktop.
'''
this snippet is used to load a web2py with postgresql 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 psycopg2
from gluon import DAL, Field
from gluon.template import render
from gluon.dal import PostgreSQLAdapter
if not (PostgreSQLAdapter.driver): PostgreSQLAdapter.driver = psycopg2
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