Using pycharm debugger using factory flask

I print more print statements than code. This is killing me.

If the flag development server is called through below, I can use the PyCharm debugger

from ersapp import app if __name__ == '__main__': app.run(debug=True) 

I follow an example in a book by Miguel Greenberg and the application manager ( flask-script ). I call the server in my application directory as shown below

 (env)$ python manage.py runserver 

and in appdirectory/__init__.py

 def create_app(config_name): webapp = Flask(__name__) ... return webapp 

The debugger in Pycharm will make it easier since when I work.

+5
source share
2 answers

You started the project manually using the CLI. To use the PyCharm IDE debugging, you must configure PyCharm for your project , and then run it using PyCharm.
But if you want to run the program without PyCharm, you can use the pdb library to debug destinations. Try using the code below:

 import pdb def my_def(): try: x = 7 / 0 except Execption as e: pdb.set_trace() 

When you run this program, you can see the interactive line on your CLI ...

+2
source

I ran into the same problem that worked through a book by Miguel Greenberg. To answer the question "How to set up PyCharm" for your project, I offer the following comment.

To stay in PyCharm to take advantage of its glorious debugger, go to “Edit Configurations” and in this dialog box, make sure that you are on the “Configurations” tab. There are two upper text fields:

Script: set the path to your manage.py

Script Parameters: runningerver

By the way, I am using PyCharm 4.5.3, although I suspect that at least some of the previous releases that I worked on do the following: now starting the application from PyCharm calls the runerver command:

 python manage.py runserver 

and this launches the jar development server, i.e. app.run (). On the "Configuration" tab, we can specify the launch of a specific script manage.py, as well as a command line argument for use, for example. as in this case. After starting the application in PyCharm, look at the top line in the output in the Run or Debug window and you will see among other entries: --file pathto / manage.py runningerver.

In the text field of the script parameter, you can specify the shell instead of runerver, in which case you would end up in the shell after starting the application in PyCharm.

The default dispatcher (application) commands are runerver and shell. The db command is added to the following manage.py line:

 manager.add_command('db', MigrateCommand) 

Under this is added a team test. Pay attention to the @ manager.command decorator before def () test.

To get a list of all manager command commands (applications) on the command line:

 python manage.py 

If you are in the Factory application part, you should see {test, shell, db, runningerver}. To get help with any type of command:

 python manage.py parameter -? 
0
source

All Articles