Posts about code snipplets
Grabbing title tag from web page

At least a couple of options, the first using BeautifulSoup:

import urllib import BeautifulSoup

soup = BeautifulSoup.BeautifulSoup(urllib.urlopen("https://www.google.com")) print soup.title.string And the second one using lxml: import lxml.html t =...

Django template filter- Show list of objects as table with fixed number of columns

I recently ran into the following problem: I needed to be able to display a list of users in a table that had a maximum of X columns. Since I could not find the solution on the Internet I decided to give it a try and here is my resulting template...

Python- Sort list of tuples by second item

Straight from the PythonInfo Wiki:

>>> import operator >>> L = [('c', 2), ('d', 1), ('a', 4), ('b', 3)] >>> map(operator.itemgetter(0), L) ['c', 'd', 'a', 'b'] >>> map(operator.itemgetter(1), L) [2, 1, 4, 3]...

Django- Reverse HTTP redirect with parameters

Here's how to, from a view, redirect to another URL passing parameters to it. For instance, to redirect the user to a certain page after login: return HttpResponseRedirect(reverse('dz_details', kwargs={'dz_id':dz.id})) This will lookup the 'dz_details'...