Static Class or Simple Functions

Having worked in a variety of other languages, my first instinct was to create classes with static methods for things like utility libraries. But after digging around Google for a bit, it seems like this isn’t necessarily the way things are done in Python:

http://stackoverflow.com/questions/12735392/python-class-static-methods

I’m not sure where I stand on this just yet. The logical argument is that classes should only be used for when you need to instantiate something. But sometimes it’s handy to make use of class variables. And really the only difference is a small change in syntax:

Django Timezone Aware Dates

UPDATE: Looks like this shortcut method does the same thing (as long as USE_TZ = True in your settings):

The following will create a timezone-aware datetime object:

Read more here: https://docs.djangoproject.com/en/dev/topics/i18n/timezones/

Checking if a GET Variable Exists in Django

http://stackoverflow.com/questions/2422055/how-to-check-if-request-get-var-is-none

First, check if the request.GET dict contains a parameter named q:

Now ensure the variable has a value:

Multiple Files for Django Views

Separating your views into multiple files works much the same way as models except for one difference – importing the views in __init__.py isn’t necessary unless you want to type a little less.

Without importing them in __init__, you’ll need to do this:

But if you add them, you can do the following instead: