Configuring pydev to work with django

Google Cache地址:
http://203.208.37.104/search?q=cache:9IIcgWt3h9oJ:pydev.blogspot.com/2006/09/configuring-pydev-to-work-with-django.html+pydev+django&hl=zh-CN&ct=clnk&cd=1&gl=cn&client=firefox-a&st_usg=ALhdy2_yM_1JnQk5s61bEqlJ_oYU7UaCaA
原文地址:
http://pydev.blogspot.com/2006/09/configuring-pydev-to-work-with-django.html

考~翻译了半天,一提交没了。气死我了。不干了。CSDN的破博客!!对Ubuntu+FF支持如此差~

Friday, September 29, 2006

Configuring pydev to work with django

Ok, some time ago I've covered how to configure pydev to work with Turbogears, and since them, I've been having some requests to do the same for Django, so... here we go ;-)

As with Turbogears, I still don't have any previous experience working with Django, so, it may be good to see how easy it is to get started with it for others!

First step: get Django. Obvious place (after searching for it): http://www.djangoproject.com/

I started by reading the overview, and it seems to be straightforward... now on to something real: downloading it... it says it only needs python, but I didn't find information on which is the preferred version. I googled for it and it appears that it is still not working well with python 2.5, so, I'll go with python 2.4.

Second step: install

[C:/bin/Python24]python e:/Install/Dev.Python/Django-0.95/setup.py install
>> The required version of setuptools (>=0.6c1) is not available, and can't be installed while this script is running. Please install a more recent version first.


The tutorial says that it will attempt to grab setuptools if setuptools is not there, but unfortunatelly it seems it does not upgrade if a version is already there.

So, after googling a little, I found http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install and discovered that I had to download an ez_setup.py script and execute it. It appears to work without any problems, so, on to trying to install django again...

[C:/bin/Python24]python e:/Install/Dev.Python/Django-0.95/setup.py install
still gives me problems, because it requires me to be in the same folder where setup.py is...

[E:/Install/Dev.Python/Django-0.95]c:/bin/Python24/python.exe setup.py install
seems to solve it... smoke test: python -c "import django" seems to work ok

It also requires a database (as I'm just testing, pysqlite seems a good option -- I'm using version 2.3.0)

Now, on to re-configure the pydev interpreter to add those new paths... I'm kind of lazy, so, usually I just remove the interpreter and add it again, instead of figuring out just the new paths (I also thinks it's safer, as it gets all the folders it finds in the pythonpath automatically). More info on that at http://www.fabioz.com/pydev/manual_101_interpreter.html

Now, on to the actually doing something

To create a base project it provides a script, so let's do it:

django-admin.py startproject mysite

It created a 'mysite' folder with some files... still in the command line (inside the mysite folder), it says to start django with:

python manage.py runserver

And voila... it's running. Now, on to do that from inside Eclipse.

Eclipse requires your code to be under a project, so, the 'new pydev project' wizard should be used, pointing the project contents to the 'mysite' folder or to a parent folder. As there is usually much more than just code in a project -- like folders for python, c++, docs... and as in this example we surely won't have a c++ folder, the initial project structure became:
/mysite
    /docs
    /src <-- this is the folder that should be added to the project pythonpath (in the project properties)
        /mysite <-- I moved the initial files to this folder (so that we can make "import mysite" as the src is added to the pythonpath)

-- for more details on creating a project and setting the project pythonpath, check: http://www.fabioz.com/pydev/manual_101_project_conf.html

Now, on to starting the server from within pydev:
If you just run the manage.py file (just open it and press F9), it will show you a message with its usage, so, run it once and then go to the menu: Run > Run... and select the 'mysite manage.py' run and put in the program arguments runserver.

Now, running it like that leaves us without any prompt inside of the Eclipse console. Taking a closer look in the django code, it appears to have an autoreloader structure (I guess that's something common to web-servers), so, as it is actually run in another process, we won't have any output. To fix this in the testing environment (after killing the process inside of Eclipse and the other process that is still running in the computer), we can just add another argument, so, now as arguments we have runserver --noreload

Note that the Eclipse console currently does not have a Ctrl+Break, so, you have to actually kill it in the red button in the console, and to re-run the last run, just use Ctrl+F11.

Now, on to set the sqlite parameters and create the actual database -- according to the tutorial, just set the engine and file to be used for sqlite and the on to:

python manage.py syncdb

-- I usually do that stuff on a separate prompt, as it is nice to run things inside of Eclipse, but having to change the argument for each different run is not all that nice (so, an open shell is always welcome)

and created a superuser... if you configured the auto-refresh for Eclipse as in http://www.fabioz.com/pydev/manual_101_eclipse.html, a new file should be appearing in the database file for sqlite -- if you pointed it to some file inside of your project (if you still haven't the auto-refresh configure, I really advise doing it, as it can be a pain having to F5 for it to refresh the folders when some external change is done to the filesystem)

Now, keeping on with the tutorial:

python manage.py startapp polls

and copied the example from the homepage. Defining the model seems straightforward, and code-completion / code-analysis should be already working ;-)

Making the syncdb again updates my sql with the new structure (pretty nice).

Now, adding the admin interface seems pretty straightforward, and without the auto-reload, the regular debugger works pretty well -- test it by putting a breakpoint after creating the __str__ function for the Poll class in the example and pressing F11 (used to debug the last run). If you want to keep the auto-reloader and still debug, you'll have to use the remote debugger that comes with the extensions to debug, as it does not rely on having the process started from Eclipse. Check http://www.fabioz.com/pydev/manual_adv_remote_debugger.html for more details.

And I guess that's it for the pydev configuration... code-completion, code-analysis, debugger, etc. should all be working.

You can now enjoy working with django inside of pydev!

Cheers,

Fabio
posted by Fabio Zadrozny at 2:34 PM

-------------------------------
F*ck
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值