Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Hiring a Python web application developer
My client is looking to hire a new Python developer, initially for an 8 month contract. It's a home working position, we communicate mostly via Skype / email / gtalk etc. Although we do meet up in meatspace from time to time, so ideally a candidate would be in the London / Oxford area. You will be working with your truly. The projects I've been working on are in the server side of web-enabled devices. The web interface is written in Django, so you'll need the usual battery of front-end technologies; HTML, CSS, Javascript etc. We have a Twistd server which communicates with devices in the field, that my client produces. In the middle we have dynamic user interface generation from XML. So there is some genuinely interesting technology there, and more such projects planned. We need someone who is a good problem solver with a general interest in web technologies. There's also the occasionally need work with data at the bits and bytes level, so a working knowledge of C that would be a plus. See the Careers page on wildfoundry.com for the full details. -
Hiring a Python web application developer
My client is looking to hire a new Python developer, initially for an 8 month contract. It's a home working position, we communicate mostly via Skype / email / gtalk etc. Although we do meet up in meatspace from time to time, so ideally a candidate would be in the London / Oxford area. You will be working with your truly. The projects I've been working on are in the server side of web-enabled devices. The web interface is written in Django, so you'll need the usual battery of front-end technologies; HTML, CSS, Javascript etc. We have a Twistd server which communicates with devices in the field, that my client produces. In the middle we have dynamic user interface generation from XML. So there is some genuinely interesting technology there, and more such projects planned. We need someone who is a good problem solver with a general interest in web technologies. There's also the occasionally need work with data at the bits and bytes level, so a working knowledge of C that would be a plus. See the Careers page on wildfoundry.com for the full details. -
Finding the first bit set with Python
Here's a Python gotcha that I spent some time tracking down. I'm writing it up in the spirit of saving developers a debugging headache in the future. I had an integer with a single bit set, and I wanted to find the index of that bit. For example, 4 in binary is 00000100. The 1 is at the third position from the right, which should give an index of 2 – since the first position is 0. You can do this in two ways; either check each bit in turn until you find a 1, or you can use math as a shortcut. I chose the math solution: >>> import math >>> myint = 4 >>> int(math.log(myint, 2)) 2 Simple right? Finally staying awake in high school maths paid off. So simple that it was the last bit of code I suspected to be broken (spoiler: it was). This is Python 2.7 which still has two types of integer; type int and arbitrary long integer type long. I was testing with ints because that's what you get when you type 4. However the numbers I was getting out of the Django db where longs. Look what happens with the above … -
Finding the first bit set with Python
Here's a Python gotcha that I spent some time tracking down. I'm writing it up in the spirit of saving developers a debugging headache in the future. I had an integer with a single bit set, and I wanted to find the index of that bit. For example, 4 in binary is 00000100. The 1 is at the third position from the right, which should give an index of 2 – since the first position is 0. You can do this in two ways; either check each bit in turn until you find a 1, or you can use math as a shortcut. I chose the math solution: >>> import math >>> myint = 4 >>> int(math.log(myint, 2)) 2 Simple right? Finally staying awake in high school maths paid off. So simple that it was the last bit of code I suspected to be broken (spoiler: it was). This is Python 2.7 which still has two types of integer; type int and arbitrary long integer type long. I was testing with ints because that's what you get when you type 4. However the numbers I was getting out of the Django db where longs. Look what happens with the above … -
Finding the first bit set with Python
Here's a Python gotcha that I spent some time tracking down. I'm writing it up in the spirit of saving developers a debugging headache in the future. I had an integer with a single bit set, and I wanted to find the index of that bit. For example, 4 in binary is 00000100. The 1 is at the third position from the right, which should give an index of 2 – since the first position is 0. You can do this in two ways; either check each bit in turn until you find a 1, or you can use math as a shortcut. I chose the math solution: >>> import math >>> myint = 4 >>> int(math.log(myint, 2)) 2 Simple right? Finally staying awake in high school maths paid off. So simple that it was the last bit of code I suspected to be broken (spoiler: it was). This is Python 2.7 which still has two types of integer; type int and arbitrary long integer type long. I was testing with ints because that's what you get when you type 4. However the numbers I was getting out of the Django db where longs. Look what happens with the above … -
Long-term reliability test with Django
Steel rusts. Food rots. And WordPress? Well, really bad things tend to happen when it's left unattended. But this website, built by hand using Django, has held up remarkably well over time. A little history: I built this site a few years ago when Lindsay and I lived in Knoxville, TN. I was working for the E.W. Scripps company at the time, and had a full-on love affair with Django (I still do). I started working at Scripps at the beginning of the first enterprise rollout of a Django content management system (customized version of Ellington. I was not new to Django then; I began using the framework toward the end of our first stay in Roanoke. This blog was both a way for me to keep my writing chops pliable, but also to put into practice the code used by Scripps developers. It helped me understand what they were building, and apply that knowledge to my role as project manager. As new versions of Django came out, so did this blog. I stopped updating around version 1.2.3 however. But unlike a WordPress install, this app has continued to hum along dutifully. This isn't to say I recommend building apps … -
Long-term reliability test with Django
Steel rusts. Food rots. And WordPress? Well, really bad things tend to happen when it's left unattended. But this website, built by hand using Django, has held up remarkably well over time. A little history: I built this site a few years ago when Lindsay and I lived in Knoxville, TN. I was working for the E.W. Scripps company at the time, and had a full-on love affair with Django (I still do). I started working at Scripps at the beginning of the first enterprise rollout of a Django content management system (customized version of Ellington. I was not new to Django then; I began using the framework toward the end of our first stay in Roanoke. This blog was both a way for me to keep my writing chops pliable, but also to put into practice the code used by Scripps developers. It helped me understand what they were building, and apply that knowledge to my role as project manager. As new versions of Django came out, so did this blog. I stopped updating around version 1.2.3 however. But unlike a WordPress install, this app has continued to hum along dutifully. This isn't to say I recommend building apps … -
Happy Holidays from Daniel and Audrey
The Python community has been like our family. We met through the community, and many of our dearest friendships started because of the community. This year has been a very special year for us. We wrote Two Scoops of Django, and we started a little publishing company called Two Scoops Press. We traveled throughout Spain, Poland, Italy, and Croatia, teaching and helping local user groups. Daniel gave keynote speeches at DjangoCon Europe and EuroPython. We did a few book signings and got the chance to meet many of our book's readers. Now we are back in Southern California, settling into our new home together and getting ready to release the next edition of our first book. We couldn't have gotten to this point without you, our friends and readers. It is because of your feedback that we've been able to improve the next edition. We've been hard at work expanding chapters and sections that you wanted to hear more about. We've been making little changes everywhere to improve clarity and help you see what's in our heads. We've been scrubbing those typos. Audrey has been drinking lots of coffee and drawing more silly Django ice cream metaphor cartoons. Daniel has … -
Happy Holidays from Daniel and Audrey
The Python community has been like our family. We met through the community, and many of our dearest friendships started because of the community. This year has been a very special year for us. We wrote Two Scoops of Django, and we started a little publishing company called Two Scoops Press. We traveled throughout Spain, Poland, Italy, and Croatia, teaching and helping local user groups. Daniel gave keynote speeches at DjangoCon Europe and EuroPython. We did a few book signings and got the chance to meet many of our book's readers. Now we are back in Southern California, settling into our new home together and getting ready to release the next edition of our first book. We couldn't have gotten to this point without you, our friends and readers. It is because of your feedback that we've been able to improve the next edition. We've been hard at work expanding chapters and sections that you wanted to hear more about. We've been making little changes everywhere to improve clarity and help you see what's in our heads. We've been scrubbing those typos. Audrey has been drinking lots of coffee and drawing more silly Django ice cream metaphor cartoons. Daniel has … -
Happy Holidays from Daniel and Audrey
The Python community has been like our family. We met through the community, and many of our dearest friendships started because of the community. This year has been a very special year for us. We wrote Two Scoops of Django, and we started a little publishing company called Two Scoops Press. We traveled throughout Spain, Poland, Italy, and Croatia, teaching and helping local user groups. Daniel gave keynote speeches at DjangoCon Europe and EuroPython. We did a few book signings and got the chance to meet many of our book's readers. Now we are back in Southern California, settling into our new home together and getting ready to release the next edition of our first book. We couldn't have gotten to this point without you, our friends and readers. It is because of your feedback that we've been able to improve the next edition. We've been hard at work expanding chapters and sections that you wanted to hear more about. We've been making little changes everywhere to improve clarity and help you see what's in our heads. We've been scrubbing those typos. Audrey has been drinking lots of coffee and drawing more silly Django ice cream metaphor cartoons. Daniel has … -
Wordpress NextGEN gallery and "Not a valid template"
If you encounter the output [Not a valid template] on your gallery pages after you updated to NextGEN gallery 2.x and you probably moved your blog location on the server, then you should check the plugin settings. In my case, under NextGEN Basic Thumbnails the Template value pointed to a wrong path. After I fixed that, everything worked again: -
Wordpress NextGEN gallery and "Not a valid template"
If you encounter the output [Not a valid template] on your gallery pages after you updated to NextGEN gallery 2.x and you probably moved your blog location on the server, then you should check the plugin settings. In my case, under NextGEN Basic Thumbnails the Template value pointed to a wrong path. After I fixed that, everything worked again: -
Wordpress NextGEN gallery and "Not a valid template"
If you encounter the output [Not a valid template] on your gallery pages after you updated to NextGEN gallery 2.x and you probably moved your blog location on the server, then you should check the plugin settings. In my case, under NextGEN Basic Thumbnails the Template value pointed to a wrong path. After I fixed that, everything worked again: -
Automated creation of self signed SSL certificate
For developing websites with SSL on your local computer there is the need to create a self signed SSL certificate. As I often need this, I wrote this little script. You may adjust the -subj part in line 4: #!/bin/bash password="password" sudo openssl genrsa -passout pass:$password -des3 -out $1.key 1024 sudo openssl req -new -passin pass:$password -subj "/C=DE/ST=Saxony/L=Dresden/CN=$1" -key $1.key -out $1.csr sudo openssl rsa -passin pass:$password -in $1.key -out $1.key sudo openssl x509 -req -days 365 -in $1.csr -signkey $1.key -out $1.crt Usage: ./create_self_signed_ssl.sh mydomain.local -
Automated creation of self signed SSL certificate
For developing websites with SSL on your local computer there is the need to create a self signed SSL certificate. As I often need this, I wrote this little script. You may adjust the -subj part in line 4: #!/bin/bash password="password" sudo openssl genrsa -passout pass:$password -des3 -out $1.key 1024 sudo openssl req -new -passin pass:$password -subj "/C=DE/ST=Saxony/L=Dresden/CN=$1" -key $1.key -out $1.csr sudo openssl rsa -passin pass:$password -in $1.key -out $1.key sudo openssl x509 -req -days 365 -in $1.csr -signkey $1.key -out $1.crt Usage: ./create_self_signed_ssl.sh mydomain.local -
Automated creation of self signed SSL certificate
For developing websites with SSL on your local computer there is the need to create a self signed SSL certificate. As I often need this, I wrote this little script. You may adjust the -subj part in line 4: #!/bin/bash password="password" sudo openssl genrsa -passout pass:$password -des3 -out $1.key 1024 sudo openssl req -new -passin pass:$password -subj "/C=DE/ST=Saxony/L=Dresden/CN=$1" -key $1.key -out $1.csr sudo openssl rsa -passin pass:$password -in $1.key -out $1.key sudo openssl x509 -req -days 365 -in $1.csr -signkey $1.key -out $1.crt Usage: ./create_self_signed_ssl.sh mydomain.local -
"djpeewee": use the peewee ORM with your Django models
I sat down and started working on a new library shortly after posting about Django's missing API for generating SQL. djpeewee is the result, and provides a simple translate() function that will recursively translate a Django model graph into a set of "peewee equivalents". The peewee versions can then be used to construct queries which can be passed back into Django as a "raw query". Here are a couple scenarios when this might be useful: Joining on fields that are not related by foreign key (for example UUID fields). Performing filters on calculated values. Performing aggregate queries on calculated values. Using SQL statements that Django does not support such as CASE. Utilizing SQL functions that Django does not support, such as SUBSTR. Replacing nearly-identical SQL queries with reusable, composable data-structures. I've included this module in peewee's playhouse, which is bundled with peewee. Code samples Suppose we have an Event model and want to find all events in the database that are longer than 2 hours: syntax:python class Event(models.Model): start = models.DateTimeField() end = models.DateTimeField() title = models.CharField(max_length=50) two_hours = datetime.timedelta(hours=2) Event.objects.filter(???) With Django I believe you would have to use the extra() method. Edit: a helpful redditor pointed out this … -
A Django base class for all your Forms
This has served me well of the last couple of years of using Django: from django import forms class _BaseForm(object): def clean(self): cleaned_data = super(_BaseForm, self).clean() for field in cleaned_data: if isinstance(cleaned_data[field], basestring): cleaned_data[field] = ( cleaned_data[field].replace('\r\n', '\n') .replace(u'\u2018', "'").replace(u'\u2019', "'").strip()) return cleaned_data class BaseModelForm(_BaseForm, forms.ModelForm): pass class BaseForm(_BaseForm, forms.Form): pass So instead of doing... class SigupForm(forms.Form): name = forms.CharField(max_length=100) nick_name = forms.CharField(max_length=100, required=False) ...you do: class SigupForm(BaseForm): name = forms.CharField(max_length=100) nick_name = forms.CharField(max_length=100, required=False) What it does is that it makes sure that any form field that takes a string strips all preceeding and trailing whitespace. It also replaces the strange "curved" apostrophe ticks that Microsoft Windows sometimes uses. Yes, this might all seem trivial and I'm sure there's something as good or better out there but isn't it a nice thing to never have to worry about doing things like this again: class SignupForm(forms.Form): ... def clean_name(self): return self.cleaned_data['name'].strip() #...or... form = SignupForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'].strip() -
Transform Images with django-imagekit
In this video we will walk through a couple of easy ways to transform images as you need them. django-imagekit makes this fairly simple and straight forward. This video provides an introduction to using it.Watch Now... -
The search for the missing link: what lies between SQL and Django's ORM?
I had the opportunity this week to write some fairly interesting SQL queries. I don't write "raw" SQL too often, so it was fun to use that part of my brain (by the way, does it bother anyone else when people call SQL "raw"?). At Counsyl we use Django for pretty much everything so naturally we also use the ORM. Every place I've worked there's a strong bias against using SQL when you've got an ORM on board, which makes sense -- if you choose a tool you should standardize on it if for no other reason than it makes maintenance easier. So as I was saying, I had some pretty interesting queries to write and I struggled to think how to shoehorn them into Django's ORM. I've already written about some of the shortcomings of Django's ORM so I won't rehash those arguments. I'll just say that Django fell short and I found myself writing SQL. The queries I was working on joined models from very disparate parts of our codebase. The joins were on values that weren't necessarily foreign keys (think UUIDs) and this is something that Django just doesn't cope with. Additionally I was interested in aggregates … -
The search for the missing link: what lies between SQL and Django's ORM?
Edit 11/13/2013: I added some Django integration to peewee to make it (hopefully) easier to build structured queries when you need to work around the ORM's limitations. Read the docs. Any feedback would definitely be appreciated! I had the opportunity this week to write some fairly interesting SQL queries. I don't write "raw" SQL too often, so it was fun to use that part of my brain (by the way, does it bother anyone else when people call SQL "raw"?). At Counsyl we use Django for pretty much everything so naturally we also use the ORM. Every place I've worked there's a strong bias against using SQL when you've got an ORM on board, which makes sense -- if you choose a tool you should standardize on it if for no other reason than it makes maintenance easier. So as I was saying, I had some pretty interesting queries to write and I struggled to think how to shoehorn them into Django's ORM. I've already written about some of the shortcomings of Django's ORM so I won't rehash those points. I'll just say that Django fell short and I found myself writing SQL. The queries I was working on joined … -
The search for the missing link: what lies between SQL and Django's ORM?
Edit 11/13/2013: I added some Django integration to peewee to make it (hopefully) easier to build structured queries when you need to work around the ORM's limitations. Read the docs. Any feedback would definitely be appreciated! I had the opportunity this week to write some fairly interesting SQL queries. I don't write "raw" SQL too often, so it was fun to use that part of my brain (by the way, does it bother anyone else when people call SQL "raw"?). At Counsyl we use Django for pretty much everything so naturally we also use the ORM. Every place I've worked there's a strong bias against using SQL when you've got an ORM on board, which makes sense -- if you choose a tool you should standardize on it if for no other reason than it makes maintenance easier. So as I was saying, I had some pretty interesting queries to write and I struggled to think how to shoehorn them into Django's ORM. I've already written about some of the shortcomings of Django's ORM so I won't rehash those points. I'll just say that Django fell short and I found myself writing SQL. The queries I was working on joined … -
The search for the missing link: what lies between SQL and Django's ORM?
Edit 11/13/2013: I added some Django integration to peewee to make it (hopefully) easier to build structured queries when you need to work around the ORM's limitations. Read the docs. Any feedback would definitely be appreciated! I had the opportunity this week to write some fairly interesting SQL queries. I don't write "raw" SQL too often, so it was fun to use that part of my brain (by the way, does it bother anyone else when people call SQL "raw"?). At Counsyl we use Django for pretty much everything so naturally we also use the ORM. Every place I've worked there's a strong bias against using SQL when you've got an ORM on board, which makes sense -- if you choose a tool you should standardize on it if for no other reason than it makes maintenance easier. So as I was saying, I had some pretty interesting queries to write and I struggled to think how to shoehorn them into Django's ORM. I've already written about some of the shortcomings of Django's ORM so I won't rehash those points. I'll just say that Django fell short and I found myself writing SQL. The queries I was working on joined … -
The search for the missing link: what lies between SQL and Django's ORM?
Edit 11/13/2013: I added some Django integration to peewee to make it (hopefully) easier to build structured queries when you need to work around the ORM's limitations. Read the docs. Any feedback would definitely be appreciated! I had the opportunity this week to write some fairly interesting SQL queries. I don't write "raw" SQL too often, so it was fun to use that part of my brain (by the way, does it bother anyone else when people call SQL "raw"?). At Counsyl we use Django for pretty much everything so naturally we also use the ORM. Every place I've worked there's a strong bias against using SQL when you've got an ORM on board, which makes sense -- if you choose a tool you should standardize on it if for no other reason than it makes maintenance easier. So as I was saying, I had some pretty interesting queries to write and I struggled to think how to shoehorn them into Django's ORM. I've already written about some of the shortcomings of Django's ORM so I won't rehash those points. I'll just say that Django fell short and I found myself writing SQL. The queries I was working on joined … -
django-ckeditor-updated released with Django 1.6 and storage API
django-ckeditor repository wasn't updated from a long time and a lot of issues collected. With the release of Django 1.6 django-ckeditor stoped working due to "defaults" in urls.py import. I've decided to polish and release my fork as a pypi package to make it easier to install the newer version. You can install it via pip using django-ckeditor-updated as name. Current version is 4.2.1. Biggest change compared to the upstream is Django storage API usage for file uploads (to make it easier to configure and to allow using other backends than local folder - like S3 storage). Other updates give CKEditor 4.2.1 as well as Django 1.6 support (should also work on 1.4 and 1.5). This application gives you the CKEditor on a model field in Django admin or in your forms. The editor can be configured (interface) and it can upload images (with the help of pillow).