如何在 Web 应用程序中启用 Eclipse 调试功能?

发布于 2024-12-09 05:40:31 字数 3154 浏览 1 评论 0原文

我正在使用 Eclipse IDE 和 PyDev 插件为我的 Python Web 应用程序使用 Django 框架。 如何使用调试功能?

更新1 特别是使用 http://pydev.org/updates 插件

UPDATES2 我已经执行了以下操作:

.pydevproject

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>

<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Python25
</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5
</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/pi-proto</path>
</pydev_pathproperty>
<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
<path>C:\Program Files\GeoDjango\Django-1.0.2-final</path>
<path>C:\eclipse-SDK-3.7-win32\plugins\org.python.pydev.debug_2.2.3.2011100616\pysrc
</path>
</pydev_pathproperty>
</pydev_project>

ma​​nage.py

#!/usr/bin/env python
from django.core.management import execute_manager
try:
    import settings # Assumed to be in the same directory.
except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
    sys.exit(1)

if __name__ == "__main__":
    import sys
    if len(sys.argv) > 1:
        command = sys.argv[1]

    if settings.DEBUG and (command == "runserver" or command == "testserver"):

        # Make pydev debugger works for auto reload.
        try:
            import pydevd
        except ImportError:
            sys.stderr.write("Error: " +
                "You must add org.python.pydev.debug.pysrc to your PYTHONPATH.")
            sys.exit(1)

        from django.utils import autoreload
        m = autoreload.main
        def main(main_func, args=None, kwargs=None):
            import os
            if os.environ.get("RUN_MAIN") == "true":
                def pydevdDecorator(func):
                    def wrap(*args, **kws):
                        pydevd.settrace(suspend=False)
                        return func(*args, **kws)
                    return wrap
                main_func = pydevdDecorator(main_func)

            return m(main_func, args, kwargs)

        autoreload.main = main

    execute_manager(settings)

运行配置 - 参数

runserver 0.0.0.0:8001

UPDATES3 我正在关注此链接 http ://bear330.wordpress.com/2007/10/30/how-to-debug-django-web-application-with-autoreload/

但没有成功。您能指导我如何正确点击上面的链接吗?然后我将在这里更新结果。

更新4 我正在使用 Python 2.5.2、GeoDjango 1.2.7、Eclipse Indigo 和 PyDev 插件。

I am using Django framework for my Python Web Application using Eclipse IDE and PyDev Plugin.
How can I use the debugging features?

UPDATES1
particularly using http://pydev.org/updates plugin

UPDATES2
I already did the following:

.pydevproject

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>

<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Python25
</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5
</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/pi-proto</path>
</pydev_pathproperty>
<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
<path>C:\Program Files\GeoDjango\Django-1.0.2-final</path>
<path>C:\eclipse-SDK-3.7-win32\plugins\org.python.pydev.debug_2.2.3.2011100616\pysrc
</path>
</pydev_pathproperty>
</pydev_project>

manage.py

#!/usr/bin/env python
from django.core.management import execute_manager
try:
    import settings # Assumed to be in the same directory.
except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
    sys.exit(1)

if __name__ == "__main__":
    import sys
    if len(sys.argv) > 1:
        command = sys.argv[1]

    if settings.DEBUG and (command == "runserver" or command == "testserver"):

        # Make pydev debugger works for auto reload.
        try:
            import pydevd
        except ImportError:
            sys.stderr.write("Error: " +
                "You must add org.python.pydev.debug.pysrc to your PYTHONPATH.")
            sys.exit(1)

        from django.utils import autoreload
        m = autoreload.main
        def main(main_func, args=None, kwargs=None):
            import os
            if os.environ.get("RUN_MAIN") == "true":
                def pydevdDecorator(func):
                    def wrap(*args, **kws):
                        pydevd.settrace(suspend=False)
                        return func(*args, **kws)
                    return wrap
                main_func = pydevdDecorator(main_func)

            return m(main_func, args, kwargs)

        autoreload.main = main

    execute_manager(settings)

Run Configurations - Arguments

runserver 0.0.0.0:8001

UPDATES3
I am following this link http://bear330.wordpress.com/2007/10/30/how-to-debug-django-web-application-with-autoreload/

But no success. Would you guide me on how to correctly follow the above link..Then I will update the result here.

UPDATES4
I am using Python 2.5.2, GeoDjango 1.2.7, Eclipse Indigo with PyDev Plugin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手心的温暖 2024-12-16 05:40:31

要将 PyDev 配置为与 Django 一起使用,请参阅: http://pydev.org/manual_adv_django.html

所以,如果您在没有自动重新加载功能的情况下执行(当您创建新的 Django 运行时 PyDev 将自动执行此操作),您可以直接执行所有操作(即:调试器和启动不需要任何特殊的调整)。

现在,如果您想在开发时启用自动重新加载,请使用以下提示:PyDev 和 Django:如何重新启动开发服务器?(克服主进程被终止时 Django 将使子进程保持活动状态的问题)

并在以下位置查看与远程调试器相关的会话: http://pydev.org/manual_adv_remote_debugger.html了解如何在使用自动重新加载功能时将调试器附加到 PyDev(主要是,您需要启动远程调试器,但会定期添加断点和如果您在主会话之前调用 pydevd.patch_django_autoreload(),PyDev 将停止。

To configure PyDev to work with Django see: http://pydev.org/manual_adv_django.html

So, if you execute without the auto-reload feature (which PyDev will do automatically when you create a new Django run), you can do all directly (i.e.: the debugger and launching don't need any special adjustments).

Now, if you want to have auto-reload on while developing, use the tips at: PyDev and Django: how to restart dev server? (to overcome an issue where Django will leave child processes alive when the main process is killed)

And see the session related to the remote debugger at: http://pydev.org/manual_adv_remote_debugger.html to see how to attach the debugger to PyDev when using the auto-reload feature (mainly, you'll need to start the remote debugger, but will add breakpoints regularly and PyDev will stop on those provided you call pydevd.patch_django_autoreload() before you main session).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文