Category Archives: Django

Migrating from django-registration to django-allauth

I’ve been wanting to migrate away from django-registration for a while. Yes, I know it’s been the default registration package since forever and I’ve used it happily for many years. But : it’s no longer actively maintained I want to do away with the email confirmation I want to allow login using either email or…

Continue Reading →

Replace user-input field with enforced value in Django form

I’m subclassing someone else’s form; I need to remove their input field and replace it with a fixed value. class MyForm(TheirForm): def __init__(self, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) # remove unwanted field self.fields.pop(‘fixedfield’) def clean(self, *args, **kwargs): cleaned_data = super(MyForm, self).clean(*args, **kwargs) # Restore field with fixed value cleaned_data['fixedfield'] = FIXEDVALUE return cleaned_data Simples…

Continue Reading →

django-behave

I like BDD. I like cucumber. I like python. I like django. I don’t like lettuce, a commonly-used python port of cucumber, when used with django. They’ve chosen the completely daft option to use your main database when testing. I’d forgotten this, so when I discovered I’d torched my production database just because I wanted…

Continue Reading →

“AttributeError: ‘module’ object has no attribute ‘blah’”

The obvious cause of this is that the settings.py doesn’t have the directory containing blah listed in INSTALLED_APPS. A less obvious cause: you’ll also get this error if the directory doesn’t contain a file __init__.py.

Continue Reading →

Django GeoIP templatetag

I’ve published 2 template tags for use with GeoIP at geoip.py. Hope they may be of use… Usage: # Templatetag get_country_name returns the client’s country code # # Example: # {% ifequal get_country “GB” %} # do something # {% endifequal %} # Templatetag get_country sets the given variable name # to the client’s country…

Continue Reading →

Django/Ajax: a great simple tutorial

An excellent tutorial from James Bennett for your first step into combining AJAX with Django “A step-by-step walk through a simple AJAX form with Django backend”

Continue Reading →

How to make a Django ForeignKey optional

Looks like you need to have both blank=True and null=True to make a ForeignKey optional in a django model…

Continue Reading →

Django App Quick Start

How to make a quick start with a first Django application

Continue Reading →

Django search engine

To help me get to grips with Django quickly, I created a search engine of the documentation. On the off-chance this is useful to others, I made it available at http://www.hobthross.com/docs/django/phpdig/search.php (Sorry if this does not show up as a hyperlink, WordPress appears to be chewing that up and ignoring it)

Continue Reading →

Django for Python websites

I’ve just taken a look at Django for the first time, and am seriously impressed. For a while now, I’ve been trying to find a way of using Python in websites, and haven’t found anything that works well enough – Zope, Cheetah, mod_python – all seem very difficult to get the simplest thing working… But…

Continue Reading →