Here are the posts tagged with django:

Guest post series: Behind the Screens at progr.es

posted by Herman on Nov. 28, 2012, comments

I recently wrote a short two-part series of posts for the progr.es blog on how I made some of our infrastructure decisions and overcame some of the trickier technical challenges in building the progr.es real-time process management web-application.

The first post is titled progr.es Behind the ...... Read more

 

Introducing Jade for Templates in Django and Flask

posted by Herman on Oct. 30, 2012, comments

Jade is a great template engine built for Node.js, and I recently had the pleasure of using it in a Node.js project. The built-in Django templating engine and Jinja2 have always served me well when it comes to templates for Django and Flask, respectively, but I quickly fell ...... Read more

 

Creating a Custom Manager for a MongoEngine Document in Django

posted by Herman on May 4, 2012, comments
This is just a quick how-to on creating a custom manager for a MongoEngine Model in Django, similar to how you would normally create a Manager for a Model in Django. Usually in Django with a PostgreSQL or MySQL database, one would do this: class PollManager(models.Manager):     def with_counts(self): ...... Read more
 

Shorter Django Class-based Views Using Lambda Functions

posted by Herman on March 22, 2012, comments
A frequent pattern in Django Class-based Views, specifically when using it for forms, is the need to specify a success_url, like this: from django.views.generic.edit import FormView class MyView(FormView):     form_class = forms.MyForm     success_url = '/accounts/success/' However, you don't want to hardcode the URL like that, because that violates DRY ...... Read more
 

Learning Django: Where to start and what to know

posted by Herman on Feb. 3, 2012, comments
A lot of people have recently been telling me that they want to start learning Django. That's great, and I'm happy to learn that the Django community is growing! To help all of you starting out with Django, here are some tips I'd like to share: Build Something The best ...... Read more
 

Setting the Instance on a Django Model Form Class Based View

posted by Herman on Jan. 9, 2012, comments
I've been converting some of my code to the new Django 1.3 class-based views recently, and I must say that overall, it's been quite a frustration. I see the merits of class based views. It has resulted in some shorter code in certain places, and helped avoid some duplication (that ...... Read more
 

How to create separate Name and Surname inputs as one widget in Django

posted by Herman on Dec. 1, 2011, comments
Today I'll show you a nice little trick that's useful if you want your new users to input their first name and last name separately, so that you know where the separation is. This allows you to say things like "Hello, Mr. Smith" or "Hello, Keanu" on your site, instead ...... Read more
 

Automatically sending your Django blog posts to Twitter and Facebook

posted by Herman on June 4, 2011, comments
Sending your Django website posts to Twitter, Facebook, LinkedIn and a whole array of other social networks is the easiest thing imaginable. Set up a Django Feed Start by setting up a RSS feed with the Django syndication feed framework. There are very detailed explanations and examples there, so I ...... Read more
 

Django: It's DRY, but you can sink your teeth into it

posted by Herman on June 1, 2011, comments
One of Django's core principles is the concept of DRY: Don't Repeat Yourself. Overall, the framework does a fantastic job at forcing you to follow that principle by default (and it's never a bad thing). Here and there, however, we need to add some initiative. I'd like to quickly share ...... Read more
 

Create random pronounceable passwords in Python/Django

posted by Herman on May 27, 2011, comments
An oft-cited problem with Django's built-in helper password generator make_random_password is that is that the passwords are very difficult to remember. Here's a short code snippet to generate passwords of the form 'snuskdrok33', 'swuspguf12', or anything with more syllables and more or less numerals.  # adaption of: # http://stackoverflow.com/questions/5501477/any-python-password-generators-that-are-readable-and-pronounceable # originally written ...... Read more
 

How to Make Zebra-Striped Tables with Django

posted by Herman on April 26, 2011, comments
In the spirit of IronZebra, I'll post a quick and easy tutorial on how to make a zebra-striped table, such as the one below, in Django. Method 1: The Cross-Browser CSS Way The easiest way to do this is to make use of the built-in Django {% cycle %} tag. ...... Read more
 

How to add full text search to your Django app with PostgreSQL and South Migrations

posted by Herman on April 19, 2011, comments
Note: In most situations, Django Haystack is the way to go for full text search in Django. But if Haystack is overkill and you only need simple full text search without installing extra packages and having to run scheduled tasks, read on to find out how to add full text ...... Read more
 

Converting Multi-dimensional Form Arrays in Django

posted by Herman on March 31, 2011, comments
When you're working with Django and jQuery, you'll find that Django lacks some support for handling multi-dimensional form arrays. Let's say that you have a form where you don't know how many entries is to be expected, and you would like the user to add new fields as necessary. Here's ...... Read more
 

Protecting your site's cookies from Cross Site Forgery (XSS) in Django

posted by Herman on Feb. 18, 2011, comments
There's an excellent post by Jeff Atwood about protecting your site's cookies from being used in one of the most common forms of XSS attacks. What it boils down to, is to set the HttpOnly attribute on the cookies you use in your site, especially those that are used for ...... Read more
 

Installing Celery for Django

posted by Herman on Jan. 23, 2011, comments
Here's a quick and rough guide on how to install Celery for Django on Ubuntu, aimed at refreshing the memory of those who've done it before.  Install rabbitMQ (instructions here) Install Celery (detailed instructions here) easy_install django-celery On the console, type the following (change the infomation where needed, 123 is ...... Read more
 

Django: Showing the help_text of a model field as a title attribute in the form

posted by Herman on Jan. 22, 2011, comments
Maybe it's just me, but I find the standard way Django outputs the help_text on form elements quite annoying. If you use form.as_ul, it looks something like this: <li><label>Label text:</label><input type="text">This is the helptext.</li> Which is great, except it's really difficult to make it look nice. What I would rather ...... Read more
 

List of Django Model _meta fields options and methods

posted by Herman on Jan. 22, 2011, comments
I've found out that it's almost impossible to find a list of all available _meta options for models in Django. Well, here is one, for both my own and your reference. Be warned, however, that these are internal options to the Django system, and can change at any time. But ...... Read more
 

How to get comments for a certain object in Django

posted by Herman on Jan. 21, 2011, comments
The Django documentation gives very detailed explanations of how to show comments for objects in templates, but makes no reference to how to actually get the comment objects associated to a certain object when your still in the view. Well, there's a handy little function for that, called for_model, which is used ...... Read more
 

Sending the url of a thumbnail from Django with sorl.thumbnail

posted by Herman on Jan. 16, 2011, comments
Sorl.thumbnail is a fantastic (in my opinion the best) thumbnailing library for Django. The documentation isn't all that great though, and it takes some figuring out how to actually send just an URL string from Django to the template, instead of using the template tag (which is normally very useful). "Why ...... Read more
 

How to quickly create a Django edit form from object instance

posted by Herman on Jan. 11, 2011, comments
One of the great things about Django is that it makes creating forms painless and easy. However, it's not always obvious how to do certain things if you don't already know the functions. Creating an "edit form" from an existing Model object instance is one of those cases. For this ...... Read more
 

How to display a custom error page for HTTP status 405 (method not allowed) in Django

posted by Herman on Jan. 10, 2011, comments
I recently realized that, despite Django having the built-in (and very useful) @require_POST decorator, there is actually no easy way to display a nice error page if the user accidentally stumbles onto a page using a GET request (or vice-versa for the @require_GET decorator). In fact, Django doesn't even show the usual ...... Read more