Login

Snippets by wolever

Snippet List

Serve admin-media from urls.py

By default the `runserver` command does some magic to automatically serve admin media. This magic doesn't happen when using other servers like gunicorn… But this makes that magic unnecessary by using urls.py to route requests for admin media to the standard static media server. `#include <production_disclaimer.h>`

  • admin
  • admin-media
Read More

Template tags for localizing UTC times with pytz

For example: Last modified: {% localdt item.modified_utc %} ({% localtimesince time.modified_utc %}) Converts the input datetimes to the timezone specified by the localtz context variable (it can also be explicitly specified, and all those other sensible things). Input UTC datetimes can be specified using either a datetime or a timestamp. Provides `localdt`, `localtime`, `localdate` and `localtimesince`.

  • timezone
  • pytz
  • timezones
Read More

Overwriting file storage

The title says it all — a subclass of FileSystemStorage which will overwrite files. Note that saves which fail part way though will leave the original file intact (see `test_upload_fails`). Based roughly on http://djangosnippets.org/snippets/2044/ .

  • file
  • storage
  • filestorage
  • file-storage
Read More

mkrange - create a range() inside a template

Accepts the same arguments as the 'range' builtin and creates a list containing the result of 'range'. Syntax: {% mkrange [start,] stop[, step] as context_name %} For example: {% mkrange 5 10 2 as some_range %} {% for i in some_range %} {{ i }}: Something I want to repeat\n {% endfor %} Produces: 5: Something I want to repeat 7: Something I want to repeat 9: Something I want to repeat

  • templatetag
  • range
Read More

wolever has posted 5 snippets.