Skip to content

Instantly share code, notes, and snippets.

@JeffSpies
Created November 7, 2011 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffSpies/1346405 to your computer and use it in GitHub Desktop.
Save JeffSpies/1346405 to your computer and use it in GitHub Desktop.
Bottle and SQLAlchemy; Pre-main running twice
import bottle as Web
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
print 'Outside of main'
##### Database code
def setup():
print 'In setup()'
engine = create_engine('sqlite:///test.db', echo=True)
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
fullname = Column(String)
password = Column(String)
def __init__(self, name, fullname, password):
self.name = name
self.fullname = fullname
self.password = password
Base.metadata.create_all(engine)
setup()
##### Routes
@Web.get('')
@Web.get('/')
def index():
return 'Test'
#####
if __name__ == '__main__':
print 'In __main__'
try:
Web.run(host='localhost', port=8080, reloader=True)
finally:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment