简体   繁体   English

Pydev Django项目编译

[英]Pydev Django project compilation

I installed pydev and eclipse to compile a django project. 我安装了pydev和eclipse来编译django项目。 Everything looks good but one thing makes me crazy. 一切看起来不错,但有一件事使我发疯。 When i change something in the code, i click to save it and hope to see the effect of changes. 当我更改代码中的某些内容时,我单击以保存它,并希望看到更改的效果。 However, I cannot see the effect of what i change unless I terminate the program and re-run as as shown below. 但是,除非终止程序并按如下所示重新运行,否则我看不到更改的影响。 It is such a pain... 太痛苦了...

在此处输入图片说明

I used to use Pycharm, but it expired. 我曾经用过Pycharm,但是它已经过期了。 In Pycharm, when the program runs once, i do not need to run it again and again. 在Pycharm中,当程序运行一次时,我不需要一次又一次地运行它。 I can easily see the effect of my changes on the code by clicking save button. 通过单击“保存”按钮,我可以轻松看到更改对代码的影响。 Is it possible to see the same thing in pydev and eclipse? 是否有可能在pydev和eclipse中看到相同的东西? Do you guys also see this issue? 你们也看到这个问题吗?

To debug Django with the autoreload feature, the Remote Debugger must be used and a patch must be applied to your code (just before the if _name_ == "_main_" : in your manage.py module): 要使用自动重载功能调试Django,必须使用远程调试器,并且必须对代码应用补丁(在manage.py模块中if _name_ == "_main_"之前):

import pydevd
pydevd.patch_django_autoreload(
  patch_remote_debugger=True, #Connect to the remote debugger.
  patch_show_console=True
)

So, doing that, starting the remote debugger and making a regular run should enable all the regular breakpoints that are put inside Eclipse to work in the Django process with the Remote Debugger (and the --noreload that PyDev added automatically to the launch configuration must be removed). 因此,这样做,启动远程调试器并进行常规运行应该可以使放置在Eclipse中的所有常规断点能够在Django进程中与Remote Debugger一起工作(并且PyDev自动添加到启动配置中的--noreload必须删除)。

I have plans on improving that so that the debugger will automatically add tracing to spawned processes (probably for the next release), but on PyDev 3.3.3 this still requires doing this manual patch and using the remote debugger. 我有改进的计划,以便调试器将跟踪自动添加到生成的进程(可能是下一个版本),但是在PyDev 3.3.3上,这仍然需要执行此手动修补程序并使用远程调试器。


The above is related to a debug run. 以上与调试运行有关。 Now, on to the regular run... 现在,进行常规运行...

When you do a run as > pydev: django, it should create a run configuration (which you can access at run > run configuration). 当以> pydev:django身份运行时,它应该创建一个运行配置(您可以在运行>运行配置中访问它)。 Then, open that run configuration > arguments and remove the '--noreload' (leaving only the 'runserver' argument). 然后,打开该运行配置>参数并删除'--noreload'(仅保留'runserver'参数)。

Then, you can simply rerun it with Ctrl+F11 (if you've set it to launch the previously launched application as indicated in http://pydev.org/manual_101_run.html ) -- (Or alternatively you can run it with: Alt + R, T, 1). 然后,您可以简单地使用Ctrl + F11重新运行它(如果已将其设置为启动先前启动的应用程序,如http://pydev.org/manual_101_run.html所示 )-(或者,您也可以使用以下命令运行它: Alt + R,T,1)。

The only problem is that if you kill the process inside Eclipse it's possible that it leaves zombie processes around, so, you can use the pydevd.patch_django_autoreload(patch_show_console=True) as indicated above to open a console each time it spawns a new process (you can do a pydevd|<- ctrl space here to add an import to pydevd). 唯一的问题是,如果您在Eclipse中杀死该进程,则很有可能会留下僵尸进程,因此,您可以使用pydevd.patch_django_autoreload(patch_show_console = True)进行上述操作,以在每次生成新进程时打开控制台(您可以在此处执行pydevd | <-ctrl空间以将导入添加到pydevd)。

Note that this should work. 请注意,这应该起作用。 If it's not working, make sure you don't have zombie processes around from a previous session (in windows you can do: taskkill /F /IM python.exe to make sure all Python processes are killed). 如果它不起作用,请确保在上一个会话中没有僵尸进程(在Windows中,您可以执行以下操作:taskkill / F / IM python.exe以确保杀死所有Python进程)。

Another note (for when you don't actually have automatic reload): Ctrl+Shift+F9 will kill the currently running process and re-run it. 另一个注意事项(用于当您实际上没有自动重新加载时):Ctrl + Shift + F9将终止当前正在运行的进程并重新运行它。

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

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