-
-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathbasic_app_plain_sqlalchemy.py
More file actions
35 lines (25 loc) · 909 Bytes
/
Copy pathbasic_app_plain_sqlalchemy.py
File metadata and controls
35 lines (25 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from flask import Flask, render_template
from flask_debugtoolbar import DebugToolbarExtension
from sqlalchemy import Column, Integer, create_engine
from sqlalchemy.orm import Session
from sqlalchemy.ext.declarative import declarative_base
app = Flask('basic_app_plain_sqlalchemy')
app.debug = True
app.config['SECRET_KEY'] = 'abc123'
# make sure these are printable in the config panel
app.config['BYTES_VALUE'] = b'\x00'
app.config['UNICODE_VALUE'] = u'\uffff'
engine = create_engine('sqlite://')
toolbar = DebugToolbarExtension(app, sqlalchemy_engine=engine)
Base = declarative_base()
class Foo(Base):
__tablename__ = 'foo'
id = Column(Integer, primary_key=True)
@app.route('/')
def index():
Base.metadata.create_all(engine)
session = Session(engine)
session.query(Foo).filter_by(id=1).all()
return render_template('basic_app.html')
if __name__ == '__main__':
app.run()