Created
November 7, 2011 22:27
-
-
Save JeffSpies/1346405 to your computer and use it in GitHub Desktop.
Bottle and SQLAlchemy; Pre-main running twice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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