简体   繁体   English

使用 Pycharm、Vagrant、Apache 和 mod_wsgi 远程调试 Flask 应用程序

[英]Remote Debugging Flask app with Pycharm, Vagrant, Apache and mod_wsgi

I have a Windows computer running vagrant with an ubuntu virtual machine.我有一台运行 vagrant 和 ubuntu 虚拟机的 Windows 计算机。 The ubuntu virtual machine has a Flask app running on apache with mod_wsgi. ubuntu 虚拟机有一个在 apache 上运行的 Flask 应用程序,带有 mod_wsgi。 I've also setup PyCharm to use Vagrant as my remote python interpreter.我还设置了 PyCharm 以使用 Vagrant 作为我的远程 python 解释器。

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 Vagrant 共享代码文件夹并转发端口 80 => 8080

I can access my flask app in chrome by going to 127.0.0.1:8080 in Windows.我可以通过在 Windows 中转到 127.0.0.1:8080 来访问我的 Flask 应用程序。

I've also tried to follow the PyCharm guide by copying the pyhton-debug.egg and adding the following to my init .py file我还尝试通过复制 pyhton-debug.egg 并将以下内容添加到我的init .py 文件来遵循 PyCharm 指南

 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.出于某种原因,我的import pydevd似乎无法正常工作,所以我使用easy_install安装了 egg 并且它似乎没问题。

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.我还必须将 IP 地址更改为从我的虚拟机到我的 Windows 机器的 IP 地址,并在调试配置中使用这些设置。

so my __init__.py file has:所以我的__init__.py文件有:

import pydevd

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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