librelist archives

« back to archive

Question about using flask-sqlalchemy in the shell

Question about using flask-sqlalchemy in the shell

From:
Oliver Andrich
Date:
2010-06-20 @ 16:51
Hi,

I seem to misunderstand something. I am using Flask-SQLAlchemy in my project
and created a model class based on db.Model. This works like a charm. But I
wanted to toy around with some querying on the shell. I fired up bpython and
I can't use User.query. User is the model I have created. User.query is
always None. I believe the reason is, that I am working outside a request
context when working on the shell.

What do I have to do in order to be able to do this on the shell?

Best regards,
Oliver

Re: [flask] Question about using flask-sqlalchemy in the shell

From:
Armin Ronacher
Date:
2010-06-20 @ 17:05
Hi,

On 6/20/10 6:51 PM, Oliver Andrich wrote:
> What do I have to do in order to be able to do this on the shell?
Just run this:

   >>> ctx = app.test_request_context()
   >>> ctx.push()

To unset the request context use

   >>> ctx.pop()

Regards,
Armin