September 16, 2009
Topics: code snipplets, software development, tips
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] >>> sorted(L, key=operator.itemgetter(1)) [('d', 1), ('c', 2), ('b', 3), ('a', 4)]
August 28, 2009
Topics: code snipplets, computers, software development, tips
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’ name in your urls.py file, which could be defined like so:
url(r'^details/(\d+)/$', views.dz_details, name='dz_details'),
There (…)
[continue reading]
August 17, 2009
Topics: code snipplets, software development, tips
Here’s how to redirect to the login page in django, making it go to a certain view (by name) after a successful login:
login_url = '%s?next=%s' % (reverse('acct_login'), reverse('jumplog_index')) return HttpResponseRedirect(login_url)
Notes:
acct_login is django’s view name for the login page (double check this, as it might change in (…)
[continue reading]
Popular