Tag Archives: django

How to set session variables in Django unit tests.

This was super non-obvious, and I lifted code from a couple of different places. If you’ve got Django view code that gets & sets session values, you’ll want to test it properly, and the standard “self.client” from Django’s TestCase doesn’t … Continue reading

Posted in General | Tagged , , , | Leave a comment

Django + PostgreSQL + virtualenv Development setup for Windows 7

Here’s what you need to do Django development on Windows 7. As I go through the install, I’m writing down all the steps to make sure that I don’t miss any. I’m going to focus on: Python 2.7.1 from python.org … Continue reading

Posted in General | Tagged , , , , , , | 2 Comments

Cleaner pattern for
  • loops in Django templates?
  • I find myself typing stuff like this a lot: {% for item in list %} {% if forloop.first %}<ul>{% endif %} <li>{{ item.value }}</li> {% if forloop.last %}</ul>{% endif %} {% empty %} <p>No items in list.</p> {% endif %} … Continue reading

    Posted in General | Tagged , , | Leave a comment

    Both production & development settings using zc.buildout & djangorecipe

    It took me a while to figure this out, so I’m writing it down. What I wanted was to have my django.wsgi script use the production settings and to have bin/django use the development settings.  Sounds easy, right?  It’s not … Continue reading

    Posted in General | Tagged , , , , , | Leave a comment

    Django development setup on Windows

    Django development on Windows sounds easy, but there are a bunch of steps to get it all working right. Python.  Use Python 2.7 from python.org http://python.org/download/.  I recommend avoiding the 3rd party Python distributions (ActiveState, Enthought, etc.) and sticking with … Continue reading

    Posted in General | Tagged , , , , , , | Leave a comment

    Multi-dimensional dicts in Python & Django?

    The code I’m working on frequently uses multi-dimensional dicts in Python.  There is a bunch of code that seems to be always doing this: # a,b, and c have come from some external data source, QuerySet, etc. a = ‘axis_1′ … Continue reading

    Posted in General | Tagged , , , , | 5 Comments

    Announcing Parents Guild

    Just a quick note to my readers and searchers that we’ve launched our new parenting website, Parents Guild.  We’ve got question & answering, e-mail notifications, tagging, voting, and a bunch of other parenting-specific features in the works.  We’ve got about … Continue reading

    Posted in General | Tagged , , , , | Leave a comment

    Resolving circular model imports caused by Haystack & Django

    So, in converting our search to Haystack, I’ve found that some of my standalone maintainence scripts no longer work.  They had an import error trying to import some of the models. The issue is that I’ve updated my models.py with … Continue reading

    Posted in General | Tagged , , , | Leave a comment

    pprinting the Django context object

    This was non-obvious to me for quite some time, and I tried several different approaches before settling on this one: If you would like to pprint your Django Context (or RequestContext) object from within a template itself, there are several … Continue reading

    Posted in General | Tagged , , , | Leave a comment

    How to split views.py into a directory (Django, Python)

    So, I’ve been doing some Django programming on the side, and the thing that annoys me is that Django forces you to put nearly all your source code into 2 files:  models.py and views.py Being a reasonable person, I wanted … Continue reading

    Posted in General | Tagged , , , | 2 Comments