views:

578

answers:

6

Hi, I am just starting Django by reading the online django book. Could you provide productivity tips for Django web development.Code snippest? Which IDE you use? I am MySQL guy are there any benefits using PostgreSQL? I am using Linux(Ubuntu). Thanks a lot.

+2  A: 

It's really a wide question :)

I don't have any specific snippet to share but some links:

  • The documentation. Django has a really great official documentation. Few Open Source or even commercial software have such a great one, so always refer to it: http://docs.djangoproject.com/en/dev/
  • Don't miss the default django middleware stuff (session, authentication, ...)
  • http://www.djangosnippets.org/ This site hosts a lot of small or big snippets for a wide variety of tasks

As for the IDE, I personally don't use one. Vim guy :)

For the DB, it's a hard question, and it depends on what you want. If you want to get some hosting for your site, MySQL is generally easier to find. PostgreSQL used to have many features that MySQL didn't, but the difference has reduced and they now are very close. PostgreSQL outperforms MySQL on some benches, but it's generally not very important. Don't forget that Django makes it relatively easy to swich backends, so you should not worry too much about that anyway.

Zorglub
+1  A: 

My piece of advice regarding productivity is to avoid reinventing the wheel: always try to find applications that match the functionality you need before you start developing them. There are a large number of apps out on the internet that provide most of the functionality you'll ever need.

Just be sure that the application you choose is is not abandoned -- see that it is frequently updated, issues about it are responded, and its bugs get fixed.

shanyu
+14  A: 

Several tips or best-practices(some probably more programming-related or python-related, not only Django itself):

  1. Skim quickly through django docs and djangobook.com

  2. Use source version control. Be it git (sign up for github.com) or mercurial(sign up for bitbucket.com or Kiln(explained below). It will help you to manage your code and, moreover, each commit is a great driving force by letting you feel "I've done one more commit, i'm doing good, i can make even better".

  3. Uze zc.buildout. Read great introduction by Jacob Kaplan-Moss and take some time to get used to it. Source version control + zc.buildout is very powerful combination for python app deployment. I've "compiled" all the LAMP stack (nginx+apache(mod_wsgi)+supervisor+mysql+python+django+php+phpmyadmin+wordpress and many more...) inside the zc.buildout, and it takes only python bootstrap.py && ./bin/buildout command to deploy a fully customized system, which is exactly the same as the development environment. Takes time, but it's well worth it. If you need to get going quickly - you might want to postpone this to better times :)

  4. Think of a cool and challenging project and start it. Every Django developer once in his/hers life wrote a blogging app, if you can't find something what's more challenging - go for the blog app as well. Integrate at least one or two reusable Django apps in your project, for instance, 1)haystack and 2) any reusable app from pinaxproject.

  5. Make your project simple enough so not to get bored in the middle of it, but add as much features requiring usage of different parts of Django as possible. Besides Models, Views, Templates, urlconf, use Forms, Authentication, implement Memcache, write your custom Middleware, use Sessions functionality, write your custom manage.py command... This will let you get more comfortable with all the separate parts of Django.

  6. After "Hello world", write one unit test and one doctest. For whatever functionality you implement later one, think which of the two types of tests suites better to test it and write a test. This will save you from swearing a lot in the future:)

  7. Plan/manage your project. Sign up for Basecamp or Fogbugz. I use the latter, as i found it being more software-development-project related and as it has got great integration with Kiln mercurial repositories hosting service(a great alternative to bitbucket.com, mentioned in 1). It has free "startup" edition which is free for up to 2 developers. This will help you from getting bored in the middle of a project.

  8. Get used to your IDE/text editor. I was too lazy to hack vim to fully meet my needs, so went for Wing IDE. It(paid version,30-day trial available) has some great features, such as 1)autocomplete (works perfectly when you add the directory, generated by zc.buildout's omellete recipe to the python path) or 2) runtime-editing (a term, invented by me:). You simply add a breakpoint in the last line of your code, launch integrated WingIDE debugger, and can keep on editing by having autocomplete access to the methods of objects, that are only created on runtime(for instance, the list of the fields, returned by django-sphinx queryset, which itself is generated after querying sphinx engine/database). You need to patch zc.buildout's bin/python script in order to get python or Django shell integrated in the WingIDE, but once you manage all that, it's a really powerfull tool. Check out PyDev plugin for Eclipse as another option, heard good things about it. Sooner or later, you'll need to make your IDE/text editor serve for your productivity. The sooner you start, the sooner you'll be able to focus only in coding.

  9. Learn to debug your Django app. I've wrote a step-by-step tutorial how to debug a Django app with winpdb. Once you get the idea of how it's done, it's easy with any debugger.

The answer turned out to be "The best pracices for programming Django", not only productivity tips, but hey, at the end of a day, isn't that the same? :)

Good luck!

P.S. Stick with MySql if you're familiar with it, save your time for 1-9 :)

Update: Three tips for increasing productivity(for everything you do with your computer, including developing with Django:)

a) If I would be asked a single best productivity tip for coders, this is what it would be: unless you are facing a problem that is show-stopper for achieving the goal you have targeted, the only website you should browse is The Ultimate productivity Blog .

b) Track what you are Actually doing while working on a computer. Gtimelog is a simple Gtk+ application written in python which perfectly serves this purpose. Check it out here. It's amazing for couple reasons a)Integrates well with Gnome - allows you to see how long are you working on a given task by just looking at the Gnome's notification area(system tray). b)It's BEST feature, in comparison to some similar tools I've used, is that you don't have to enter the time you plan to devote for a given task. You just enter when u finish a task, and the program calculates how much time it took you to do it. All the apps that do opposite will fail, as no one likes to realize "oh fcuk, i'm two hours behind my plan, i'm failing...". Rescue Time is a similar tool, with many more advanced features and completely automated tracking, sadly, it's got no linux version, only some hacked version, which, when i have been looking at it, had only half of the functionality of the original. Last not least - GTimeLog is originally coded by Marius Gedminas, which makes me proud being Lithuanian :)

c) Get a big monitor. Even better - two big monitors:) 22'' is not enough for WingIDE's two code-editing windows (79 characters, Python standard, each) + file browser (Ubuntu Gnome). 24'' would be perfect.

toinbis
great answer (fogbugz would be the 'latter' though not former :)
Jiaaro
Jim, Cheers for letting me know! That's the problem of having worked as a journalist for a while - you tend to stop doing enough proof-reading, as there's always a corrector and an editor who will re-read your text and correct what you haven't spoted:) Not an excusem though :)
toinbis
toinbis, I have fixed your hyperlinks.
Ben James
Ben, many thanks!
toinbis
Thanks dude! Nice recommendations
Gok Demir
The Ultimate Productivity Blog is a great blog now I am a big follower
Gok Demir
+2  A: 

If you love Vim and want to use it as your Django IDE check out http://code.djangoproject.com/wiki/UsingVimWithDjango.

I am MySQL guy are there any benefits using PostgreSQL?

I don't have great experience using PostgreSQL, but Jacob (co-founder of Django) seems to love it. Reference: http://www.youtube.com/watch?v=p-WXiqrzAf8

Kenny M.
+1  A: 

My first lines of code in Eclipse with the PyDev module worked great.

If you're doing Java stuff in Eclipse, then doing your Python/Django stuff in Eclipse too is a good idea. If you don't use Eclipse, then I can image that there better IDE's for Django development.

BTW After using CVS for some years, it took me some time to switch to GIT. But now I do love it.

robertnl
+1  A: 

In addition to the answers you received, I would like to say that:

  • I am using PyDev and Komodo Edit and both of them are very good. I have a little preference for Komodo Edit when I work with html and css content.

  • Django book is a must-have. It covers main aspects of webapp development. I've learned many things with this book.

  • The biggest problem I've faced with Django is the modifications of the model. Executing SQL is not very connvenient. I am evaluating South on a new project and it seems to be the solution of this problem.

I hope it helps

luc