-
Notifications
You must be signed in to change notification settings - Fork 0
1.5.8 Integrasi dengan Python Shell
David Rigan edited this page Feb 13, 2020
·
1 revision
Integrasi ini berfungsi ketika kamu menjalani flask shell, dengan integrasi kamu tidak lagi mengimport objek yang akan digunakan. Nah, kamu akan menggunakan app.shell_context_processor decorator.
Taruh kode ini di paling bawah:
# app.py: integrasi dengan python shell
...
@app.shell_context_processor
def make_shell_context():
return dict(db=db, User=User, Role=Role)Fungsi shell_context_processor mengembalikan hasil dict kedalam flask shell.
$ flask shell
>>> app
<Flask 'app'>
>>> db
<SQLAlchemy engine=mysql+pymysql://root:***@localhost/flask_web_development?charset=utf8>
>>> User
<class 'app.User'>
>>> Role
<class 'app.Role'>Referensi :
- Miguel Grinberg - Flask Web Development, Developing Web Applications with Python