简体   繁体   中英

Remote Debugging Flask app with Pycharm, Vagrant, Apache and mod_wsgi

I have a Windows computer running vagrant with an ubuntu virtual machine. The ubuntu virtual machine has a Flask app running on apache with mod_wsgi. I've also setup PyCharm to use Vagrant as my remote python interpreter.

I can debug a script fine but I can't seem to find a way to debug the actual flask app which is running.

Vagrant has the code folder shared and forwards port 80 => 8080

I can access my flask app in chrome by going to 127.0.0.1:8080 in Windows.

I've also tried to follow the PyCharm guide by copying the pyhton-debug.egg and adding the following to my init .py file

 if __name__ =='__main__': app.run(host='0.0.0.0', port=80, threaded=True) import sys sys.path.append('/home/vagrant/code/Flask-App/pycharm-debug.egg') import pydevd pydevd.settrace('0.0.0.0', port=8080, stdoutToServer=True, stderrToServer=True)

For some reason my import pydevd didn't seem to work properly so I used easy_install to install the egg and it seems to be OK.

I also had to change the IP address to the IP address from my virtual machine to my Windows machine and use these settings in the debug configuration.

so my __init__.py file has:

import pydevd

pydevd.settrace(
    '10.0.2.2', 
    port=80, 
    stdoutToServer=True, 
    stderrToServer=True
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM