Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

495
Views
How to run flask shell in PyCharm?

I created new flask project in PyCharm but I can't see how to run flask shell in integrated PyCharm python console window.

Name app is not defined when start console: Name app is not defined when start console

I still can run command "flask shell" in integrated PyCharm terminal but it will start without code completion, hints, syntax checks, etc.

Flask app is defined in terminal:

Flask app is defined in terminal Is there any way to start flask shell in integrated PyCharm python console?

over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

Running a Shell

To run an interactive Python shell you can use the shell command:

flask shell

This will start up an interactive Python shell, setup the correct application context and setup the local variables in the shell. This is done by invoking the Flask.make_shell_context() method of the application. By default you have access to your app and g.

It's just a normal interactive Python shell with some local variables already setup for you, not an IDE editor with code completion, hints, syntax checks, etc.

over 4 years ago · Santiago Trujillo Report

0

You can use a combination of creating a request context for the Shell (which flask shell does) and a custom starting script for the PyCharm console.

Where to enter starting script in PyCharm preferences

# Step 1: acquire a reference to your Flask App instance
import app
app_instance = app.create_app()
# I return app instance from a factory method here, but might be be `app.app` for basic Flask projects

# Step 2: push test request context so that you can do stuff that needs App, like SQLAlchemy
ctx = app_instance.test_request_context()
ctx.push()

Now you should have the benefits of flask shell alongside the code completion and other benefits that IPython Shell provides, all from the default PyCharm Python Shell.

over 4 years ago · Santiago Trujillo Report

0

In my case (in my server.py I had app=Flask(__name__)) I used

from server import app
ctx = app.app_context()
ctx.push()

Then added this to File | Settings | Build, Execution, Deployment | Console | Python Console starting script

over 4 years ago · Santiago Trujillo Report

0

This also works:

from app import app
ctx = app.test_request_context()
ctx.push()

more on the Flask docs page

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!