Category Archives: Python

How to get current year, month, day, etc. in python

Ok, so you have been coding for quite some long hours this week and you suddenly realie you dont even know what day it is. Or even year (yes, it happens). Since you are on the python command line, here’s what you can do: (ok, so the scenario could be slightly different…still, the method to… Read More »

Django template to respect plain text field linebreaks

If you have a text field with linebreaks in your nice django admin and your cool template refuses to respect them, use this in your template: this replaces newlines with HTML and newlines with blank lines with Learn tons of great stuff from your trusty Django docs: – Built-in template tags and filters

Remove repeated adjacent characters from string

Given a string like: “aabbdeeeef” or “bbbbbbb” we want to output: “abdef” and “b” respectively. here are a few ways to do it in Python:

Quickly change a Django user password

So you have this nice django site, you try to access the admin to change some minor thing and you completely forgot (and didnt save somewhere) the password of the only user in the system – so many dont’s in that sentence, but anyway… Since you are the developer, you can simply do this (assuming… Read More »

How to add robots.txt to a Django project

So we had this nice, unfinished project, publicly shared on a public server being indexed like a pig’s behind on google servers. Some searches on google had hits to full length urls to this unfinished project on the test server. Easily stopped using the robots.txt, except that its a Django site and its not as… Read More »

How to check Django version

Warning: count(): Parameter must be an array or an object that implements Countable in /home/wwwmani/public_html/42/wp-content/plugins/wp-shkshell/wp-shkshell.php on line 59

Since we are in the version theme, here’s how to check what version of django is installed in your python: From your python prompt: >>> import django >>> django.VERSION you will get something like this: $ (1,2,7, ‘final’, 0) Versions depending on your installation. Or you can type this on your command prompt (windows): c:\whatever>… Read More »