We were talking about things that we wish we had known before while developing for Django the other day in IRC. I proclaimed that we should write them down somewhere. So I’m writing a post to get this effort started. Please feel free to leave comments with your own tips and tricks, and I’ll compile them in some kind of good fashion. These are mostly just pointers, and not full-blown writeups, just more of a big list of stuff you should think about. I think these tips will really help out new people when they’re trying to get the hang of Django.

App level¶

Local library installation¶ When you don’t have root access on a machine, and you want to use easy_install, you can install files into a designated directory. I use ~/lib to hold my python modules, so when I do easy_install I simply use the -d option like so: easy_install -d ~/lib nose

Use iPython¶ IPython is a python distribution that gives you lots of handy features like tab completion, syntax highlighting, better debugging, and lots of other nice features. Poke around, I find more and more stuff I like every time.

Use django command extensions¶ This is one project I use every time I do some new code. I wrote up a whole post and screencast about how good they are. They have gotten even better since then, highly recommended.

Performance tips from the man himself¶ Jacob (co-BDFL) wrote up some performance tips back in ‘05 that are still relevant today. Some big architectural stuff, but they still make sense.

Use mod_wsgi¶ mod_wsgi is currently the best way that I know of to run Django. I did a simple write up a while back that has proved popular.

Running out of memory?¶ Web faction has a good blog entry about how to keep memory usage down. Might be useful even if you’re not running on their hardware.

Use pdb¶ Pdb is a great debugger. Simon has a great post on it, and I took a lot of his ideas and expanded them to do my debugging django screencast series. Using pdb

Read b-list.org archives¶ My tips here are short and sweet, James has a wealth of amazingly informative Django information stowed away in his blog archives. Do yourself a favor and peek through it and be enlightened.

Don’t be afraid of Reusable apps¶ Watch James’ presentation on Reusable apps at Djangocon. Learn it, and use it. A lot of the functionality that you want to do has already been done for you. Check out Pinax which has a ton of nice reusable apps. django-basic-apps also has a ton of really nice reusable apps that use best practices. I use the blog here and it’s a great way to learn how to use django well. Learn by other people’s awesome examples!

Watch the Djangocon videos¶ The videos from Djangocon give you some great insights into Django.

Search and replace¶ Search and replace across an entire directory. This is useful for changing template vars or doing basic refactoring (good editors should do this for you too) perl - pi - w - e 's/foo/bar/g' *. html

Check out virtualenv¶ virtualenv is an awesome python tool that allows you to create mini-sandboxes of python. You can contain an entire django install (and supposedly you can get mod_wsgi and some other stuff inside). I haven’t played with it too much, but it sounds really nice to keep a contained python environment, and allows you to run different versions of libraries, django, and anything else you can think of.

Use Django snippets¶ Django snippets is a great place to post your tips, or get other peoples code examples. It’s a big cookbook of helpful and neat things about django. It doesn’t have search, so use google’s site:djangosnippets.org syntax to find what you need.