Guest User

Untitled

a guest
Nov 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. from flask import Flask
  2. from flask.ext.admin import Admin
  3. from flask.ext.admin.contrib import sqlamodel
  4.  
  5. from sqlalchemy import create_engine, Column, Integer, Unicode
  6. from sqlalchemy.ext.declarative import declarative_base
  7. from sqlalchemy.orm import scoped_session, sessionmaker
  8.  
  9. Base = declarative_base()
  10.  
  11.  
  12. class User(Base):
  13. __tablename__ = 'user'
  14.  
  15. id = Column(Integer, primary_key=True)
  16. name = Column(Unicode(64))
  17.  
  18.  
  19. # Create application
  20. app = Flask(__name__)
  21. app.config['SECRET_KEY'] = '123456790'
  22.  
  23. # Create SQLA session
  24. engine = create_engine('sqlite:///dummy.sqlite')
  25. Base.metadata.create_all(engine)
  26. session = scoped_session(sessionmaker(bind=engine))
  27.  
  28. # Flask initialization here
  29. admin = Admin(app)
  30.  
  31. # Pass a session object here. You might want to store it elsewhere.
  32. admin.add_view(sqlamodel.ModelView(User, session))
  33.  
  34. # Start app
  35. app.debug = True
  36. app.run()
Add Comment
Please, Sign In to add comment