Django+Eclipse with Code Complete Screencast

June 10th, 2009 | Tags: , , ,

Here is my first screencast, finally polished off.  In it, I discuss how to set up the Eclipse IDE to do your Python and Django development, complete with code complete, jump-to-code functionality and live  breakpoints + code replace.  I’ve recently migrated away from Textmate (a large reason for this was wanting to develop on both Linux and OSX) and found that Eclipse has really sped up learning Django and some of the libraries I’ve used.
I reference a few URLs for this screencast.  They are:

I also reference a chunk of code that your manage.py should be.  I’ve uploaded that to snippet to django snippets.  It was originally posted here in 2007, so I’ve copied it to Django snippets in case that post disappears.

With that all said and everything out of the way, here is the video.  Please let me know if you have any questions! (In case you’re wondering, I used IShowU HD Pro to record this and iMovie to edit [badly].)


View on Vimeo.

Pass it along:
  • Facebook
  • Digg
  • Reddit
  • E-mail this story to a friend!
  • santhoshejanthkar
    Hi,

    this is video is good to know how to configure python in eclipse and do small debugging in aplication.

    Thanks and regards
    Santhosh Ejanthkar
  • andrewsimpson
    Great screencast. 3rd time I've tried getting it up, but with much frustration the first 2 times. You made this attempt effortless.

    A note on how to avoid the database mislink you had that you fixed by changing the folder context, I can't recall where I got this, perhaps the Dango-From-The-Ground-Up screencast

    import os
    PROJECT_DIR = os.path.dirname(__file__)
    ...
    DATABASE_ENGINE = 'sqlite3'
    DATABASE_NAME = os.path.join(PROJECT_DIR, 'database.db')

    Nice little trick to avoid relational path issues when deploying your server as well
  • Great stuff - thanks for this informative and helpful screencast. Looking forward to getting my hands dirty with Django!
  • johnstoner
    Got through to the end with my own project using Bitnami's Djangostack, and it almost works. In the debug perspective, the debugger displays the right methods in the stack, and the right variables set in the variables window, but the code display window is displaying the wrong line of code. It's about 70 lines off. Any ideas?
  • Nice screencast!!
  • cmsjr
    Super helpful, many thanks..
  • Great screencast and a big help for people like me, who used Firebug as debug device ;)
  • rhodium
    Super article — This will definitely get a repost. I actually have listened to this 3 times now including pausing to work through this. As others have pointed out --noreload is essential. I do have a question about test driven development. I tend to code up my tests under tests.py (i.e. polls/tests.py). Then from the command line I am able to python manage.py test polls. And in the past this just works. I was able to modify the django snippet to facilitate this so it once again works via the command line. I have to ask is this how you work or do you simply develop in the manner you demonstrated. I know it's a loaded question but I am curious??

    Thanks -- Again super job -- this really helped!!
  • Hi Rhodium -

    I basically use eclipse for a large portion of the actual django development, but still keep a console open at all times to do some console based manage.py commands (including testing. )

    What I've done, to make this a little easier, is to rename the manage.py from above to 'debug-manage.py' and use that in Eclipse. I then continue to use the real manage.py for all my command line work (my development model is usually: develop models first, use the models in the shell to see if they meet my needs, refine models, and then when I'm comfortable start with the layer above -- usually by doing URLs first for the model's REST implementation.)

    Hope this helps at all?

    -Nick
  • Great tutorial! I should point out that PyDev extensions is now open source (and free as in beer) at http://pydev.org/. So, no more 30-day trial or $45 needed.
  • Karl
    Awesome screencast.

    If anyone else is having a problem (like me) where pressing the red stop button after debugging leaves the server running, the solution is to add --noreload to the arguments after runserver (around 14:20 in the video). This will not only keep the process from staying alive in the background, it will give you the webserver output in the eclipse console.
  • Great suggestion Karl. I've started doing that too. The only side-effect to that approach is that you have to restart your Django instance when you change some code, but most of my apps come up pretty quickly so its not as much a dealbreaker as it sounds.
  • trendymoniker
    is there a way to automatically restart the django instance on code change? if not, how do you do it manually?
  • Sergio
    great screencast!

    That should be mentioned in the django documentation!!!
  • Great video. Thanks for taking the time to share you knowledge with us.
  • iscrow
    Awesome! Thanks Nick! This helped A LOT!
  • Adam N
    For future reference (regarding minute 12), I noticed (for me at least) that it required ctrl+shift+o to tell code completion to load the variables in the actual app.
  • Adam N
    I'm trying to do this method with a new Pinax (trunk) installation - with difficulties. I think it's virtualenv and they're (frustrating?) method of running manage from within a source directory.

    Anybody else try this?
  • While stopping debugger(clicking red button) it takes like mins to stop!! Any thoughts?
  • In OSX, I was having some issues with the red stop not working. I end up just using kill from the terminal (which I have open anyway to do other python-y things.) Seems to work ok in Linux for me though (I have no reason why one is different than the other...)
  • How do I kill those processes?
  • From the terminal, I would do a:

    ps awux | grep manage

    This should find the django python manage.py process. The second column is the PID (process ID.) You could then kill PID (or kill -9 PID if that doesn't work.) That should kill the process.
  • Thanks a lot, this really helped! but still sometimes the debugger does not just run.
  • I got debugger working properly. I was missing your piece of manage.py. But now I cant access shell from command line i.e. python manage.py shell does not start anything. Any thoughts?
  • Infact none of python manage.py options work
  • This is because you don't have the pydev module in your classpath (remember we added that in the eclipse run configuration in the screencast?)

    You have to manually add that to your python system library path. One way to do that is at the top of your manage.py add:

    import sys
    sys.path.append("/wherever/that/pydev-module-is/on/yourmachine")
  • how will I use debugger then? I dont mind running it from command line..
  • Great tutorial. Thank you!

    Is there any way to get code completion of arguments for the classes? For example: models.CharField( max_length=int, etc or anyway to show these arguments for the CharField in a help panel?
  • Would love to see if someone figured that out. I've never been able to get it to work.
  • This is really great. How do I get Django to stop running once I initiate it? Right now I have to open Activity Monitor and forcefully kill it.
  • Thanks very much for your tutorial. It saved me a lot of time trying to figure out how to do this.
  • Miles
    Great screencast - thanks for putting it together. One area you didn't touch on was the editing of Django templates. Are there any particular plugins that you use to ease the creation of these?
  • Sadly, I haven't gotten the template support to be completely 100% yet. I read this post recently: http://www.beardygeek.com/2008/11/django-templa... but haven't tried. Might be worth giving a shot. I'll report back with how it looks to me.
  • Thank you for the excellent screencast. I managed to get the remote debugger working but it only works sometimes. If I stop the debuggers and then start them again - the breakpoints are never hit. But sometimes it does work and I can't figure out under what circumstances, any ideas why it would work intermittently?

    Phil
  • In answer to my own question in case anybody else experiences the same issues.

    Two reasons for the intermittent behaviour:
    1. Firefox in all it's wisdom was using port 8000 as a loopback - changing server to run on another port solved this.
    2. I stupidly had caching still enabled and as such the views were not being hit.

    Phil
  • Dolan A.
    I was pulling my hair out trying to figure out why breakpoints were not working! Thanks for sharing your solution.

    Note to all others with this problem, you can change the port by modifying the Arguments in the Debug Configurations (e.g. "runserver" becomes "runserver 127.0.0.1:8080").
  • tony
    Thanks very much for this -- it's very clear and easy to follow!

    cheers!
  • Really great information, tks a lot.
  • By the way, you said you would put the urls for software updates etc. but I don't see it.

    I've been using pyDev for about a 9 months now and really like it, since it was bought by Aptana the development for it has been going pretty fast and new versions are arriving reasonably frequently.
  • FYI. The pydev buttons are not there to be added on my versions under windows. Using 1.4.6.2788 and eclipse 3.42.

    Also, I've never had that problem with the path to the database. Your not using relative SQLite paths are you? thats bad :p
  • Very strange... i used that same version of PyDev when I did the screencast. Make sure to install PyDev extensions (the buttons aren't in PyDev.)

    Once you do that, the buttons have to be added to the PyDev perspective (although its in the debug perspective by default). Adding them to the PyDev perspective is pretty subtle... right click on the tool bar, click on "customize perspective", go to "Commands" and check the "PyDev Debug" checkbox and then push "OK". That should add them (worse case scenario, they should be in the debug view.)

    In terms of the update site, I think its up there in the post. The update site is to install PyDev+Extensions is http://www.fabioz.com/pydev/updates . Any other URLs that I might be missing (I might have mentioned something that I forgot about.)

    Using SQLite is bad in general :). I don't refer to things relative or absolute for most of my real world (it causes nightmareish deploy scenarios across QA and Prod). I have the code introspect its path and then build the paths appropriately. I'll probably make a post about that later -- I've been bitten by the "oh shit, I forgot to change the template dir path for prod" deploy issue before.

    Thanks for the comments!
  • Sasha
    Great screencast,
    I'm using Ubuntu and was using gedit + plugins to code my django.. but now..
    Thank you.
blog comments powered by Disqus