问题描述
我使用Eclipse IDE和PyDev Plugin为我的Python Web应用程序使用Django框架。如何使用调试功能?
UPDATES1
特别是使用插件
更新2
我已经做了以下工作:
.pydevproject
<?xml version =1.0encoding =UTF-8standalone =否?>
<?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#假定是在同一个目录。
除了ImportError:
import sys
sys.stderr.write(错误:在包含%r的目录中找不到文件'settings.py'。事情,你必须运行django-admin.py,传递你的设置module.\\\
(如果文件settings.py确实存在,它会导致一个ImportError。)\\\
%__file__)
sys.exit(1)
如果__name__ ==__main__:
import sys
如果len(sys.argv)> 1:
command = sys.argv [1]
如果settings.DEBUG和(command ==runserver或命令==testserver):
#使pydev调试器适用于自动重新加载。
尝试:
import pydevd
除了ImportError:
sys.stderr.write(错误:+
您必须添加org.python.pydev.debug。 pSrc到你的PYTHONPATH。)
sys.exit(1)
from django.utils import autoreload
m = autoreload.main
def main(main_func,args =没有,kwargs =无):
import os
如果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
我正在关注此链接
但没有成功。你能指导我如何正确地遵循上述链接。然后我将在这里更新结果。
UPDATES4
I使用Python 2.5.2,GeoDjango 1.2.7,Eclipse Indigo与PyDev插件。
配置PyDev与Django配合使用请参阅:
所以,如果你执行没有自动重新加载功能(PyDev会在你创建一个新的Django运行时自动执行),你可以直接执行所有操作(即:调试器和启动不需要任何特殊的调整)
现在,如果您想在开发过程中自动重新加载,请使用以下提示:(以克服Django将让子进程活着的问题当呃n进程被杀死)
请参阅与远程调试器相关的会话:,以了解如何在使用自动重新加载功能时将调试器附加到PyDev(主要是您需要启动远程调试器,但将会定期添加断点,PyDev将停止在主会话之前调用pydevd.patch_django_autoreload()的那些。)
I am using Django framework for my Python Web Application using Eclipse IDE and PyDev Plugin.How can I use the debugging features?
UPDATES1particularly using http://pydev.org/updates plugin
UPDATES2I 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
UPDATES3I 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.
UPDATES4I am using Python 2.5.2, GeoDjango 1.2.7, Eclipse Indigo with PyDev Plugin.
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).
这篇关于如何在Web应用程序中启用Eclipse调试功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!